IPHONE 开发 6 -- Object C 02 常用数据类型[整型浮点型,短长整型],数组(固定长度,变长)

常用数据类型与c语言基本一样 难怪是c语言的超集

 

1.整型 (int) 浮点型 (float, double)  短长整型(short, long)

  int,[float,double],[short,long]

  int i=0;

  float i=1.1;

  double i =2.2;

   short int i =200;

  long int i=11111111111111111112456L;

 

  1. //整型
  2.     int i = 100;
  3.     //浮点型
  4.     float f = 1.1;
  5.     //双浮点型
  6. double d = 2.2;
  7.     //短整型
  8.     short int si = 200;
  9.     //长整型
  10.     long long int ll = 123324123234123L;
  11.    
  12.    
  13.     //输出数据与内存中所占字节数
  14.     //整型
  15.     NSLog(@"i = %d size = %lu byte ",i, sizeof(i));
  16.     //浮点型
  17.     NSLog(@"f = %f size = %lu byte",f,sizeof(f));
  18.     //双浮点型
  19.     NSLog(@"d = %e size = %lu byte",d,sizeof(d));
  20.     //短整型
  21.     NSLog(@"si = %hi size = %lu byte",si,sizeof(si));
  22.     //长整型
  23. NSLog(@"ll = %lli size = %lu byte",ll,sizeof(si));

 

2.字符串 NSString*  与  char*  
    NSString * str=@"string";

    char * chr="a1212231";

  1. NSString * str = @"MOMO";
  2.     char *c = "15810463139";
  3.     //将NSString 转换为char *
  4.     const char *change = [str UTF8String];

  5.     //输出log
  6.     NSLog(@"str = %@ size = %lu", str,sizeof(str));
  7.     NSLog(@"c = %s size = %lu", c, sizeof(c));
  8.     NSLog(@"change = %s size = %lu", change, sizeof(change));

 

3 字符串格式化stringWithFormatFormat

   NNString * str=stringWithFormat:@"name is %@:

posted @ 2012-06-25 17:21  大树2  阅读(2855)  评论(0编辑  收藏  举报