【Object C】 基本数据类型

本文从Hello,Object-c 开始,通过程序介绍Object C 下常用数据类型

#import<Foundation/Foundation.h> //import不会重复包含头文件,include不会自动防止重复包含头文件
#include<stdio.h> //Oc 基本框架 Foundation/Foundation.h
#include"print.h" //Oc程序中可以直接调用C语言函数

/*oc中使用的基本数据类型:一般数据类型,扩展的数据类型
  
整形 intchar     扩展整形short(等价于short int),
                              long (   long int)
                              longlong( long long int )
                             unsigned short
                             unsigned long/long long

*/


intmain(intargc, const char * argv[]) {
   
@autoreleasepool {  //oc 创建内存池1
       
// insert code here...
       
NSLog(@"Hello, World!");
       
NSLog(@"Hello,Object-c");
       
hello();
       
NSLog(@"\n");
       
         
       
int i = 12;
       
NSLog(@"%i ,  %o ,  %x  , %lu",i,i,i,sizeof(int));
       
char c = 's';
       
NSLog(@"%c  , %lu",c,sizeof(char));
       
short s = 50;
       
NSLog(@"%hi ,  %ho ,  %hx , %lu",s,s,s,sizeof(short));
       
long l = 40;
       
NSLog(@"%li ,  %lo ,  %lx ,  %lu",l,l,l,sizeof(long));
       
long long ll = 80;
       
NSLog(@"%lli ,  %llo ,  %llx, %lu",ll,ll,ll,sizeof(longlong));
       
unsigned short us = 10;
       
NSLog(@"%hu ,  %ho ,  %hx  , %lu",us,us,us,sizeof(unsignedshort));
       
unsigned long ul = 19;
       
NSLog(@"%lu ,  %lo ,  %lx , %lu",ul,ul,ul,sizeof(unsignedlong));
       
unsigned long long ull = 100 ;
       
NSLog(@"%llu ,  %llo ,  %llx , %lu",ull,ull,ull,sizeof(unsignedlonglong));
       
   
       
float f = 300.1415926 ;
       
double df = 300.1415926 ;
       
long double ldf = 300.1415926;
       
NSLog(@"f  : %lu ,%f , %e ",sizeof(float),f,f);
        NSLog(@"df : %lu ,%f , %e ",sizeof(double),df,df);
        NSLog(@"ldf: %lu ,%Lf , %Le ",sizeof(longdouble),ldf,ldf);
       (注意 1、long double 的转义符应该用大写的Lf/Le
            2、float double cant be signed or unsigned
       
    }
    return 0;
}

运行结果:
2014-11-24 10:39:58.608 Hello-Oc[773:303] Hello, World!
2014-11-24 10:39:58.610 Hello-Oc[773:303] Hello,Object-c
Hello C2014-11-24 10:39:58.611 Hello-Oc[773:303]
2014-11-24 10:39:58.611 Hello-Oc[773:303] 12 ,  14 ,  c  , 4(int)
2014-11-24 10:39:58.612 Hello-Oc[773:303] s  , 1 (char)
2014-11-24 10:39:58.612 Hello-Oc[773:303] 50 ,  62 ,  32 , 2(short)
2014-11-24 10:39:58.613 Hello-Oc[773:303] 40 ,  50 ,  28 ,  8(long)
2014-11-24 10:39:58.613 Hello-Oc[773:303] 80 ,  120 ,  50, 8 (long long)
2014-11-24 10:39:58.614 Hello-Oc[773:303] 10 ,  12 ,  a  , 2 ( unsigned short)
2014-11-24 10:39:58.615 Hello-Oc[773:303] 19 ,  23 ,  13 ,8 (unsigned long)
2014-11-24 10:39:58.615 Hello-Oc[773:303] 12 ,  14 ,  c ,8  (unsigned long long)
2014-11-24 10:39:58.616 Hello-Oc[773:303] f  :4 (float) ,300.141602 , 3.001416e+02  
2014-11-24 10:39:58.616 Hello-Oc[773:303] df :8(double) ,300.141593 , 3.001416e+02
2014-11-24 10:39:58.617 Hello-Oc[773:303] ldf:16(long double) ,300.141593 , 3.001416e+02 
posted @ 2014-11-24 18:15  shujucn  阅读(380)  评论(0编辑  收藏  举报