常用数据类型与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;
- //整型
- int i = 100;
- //浮点型
- float f = 1.1;
- //双浮点型
- double d = 2.2;
- //短整型
- short int si = 200;
- //长整型
- long long int ll = 123324123234123L;
-
-
- //输出数据与内存中所占字节数
- //整型
- NSLog(@"i = %d size = %lu byte ",i, sizeof(i));
- //浮点型
- NSLog(@"f = %f size = %lu byte",f,sizeof(f));
- //双浮点型
- NSLog(@"d = %e size = %lu byte",d,sizeof(d));
- //短整型
- NSLog(@"si = %hi size = %lu byte",si,sizeof(si));
- //长整型
- NSLog(@"ll = %lli size = %lu byte",ll,sizeof(si));
2.字符串 NSString* 与 char*
NSString * str=@"string";
char * chr="a1212231";
- NSString * str = @"MOMO";
- char *c = "15810463139";
- //将NSString 转换为char *
- const char *change = [str UTF8String];
- //输出log
- NSLog(@"str = %@ size = %lu", str,sizeof(str));
- NSLog(@"c = %s size = %lu", c, sizeof(c));
- NSLog(@"change = %s size = %lu", change, sizeof(change));
3 字符串格式化stringWithFormatFormat
NNString * str=stringWithFormat:@"name is %@: