sizeof(char*)

sizeof(char),sizeof(char*),sizeof(char[4]),

Deadly 提交于 2020-02-29 20:34:25
32位系统,地址长度是32位(bit),也就是4Byte; 64位系统,地址长度是64位(bit),也就是8Byte 运用1: char a[] = "hello world"; //自动为末尾加上'/0' char b[14] = "hello world"; char *p = a; char *dd = "01234"; NSLog(@"%ld", sizeof(a)); NSLog(@"%ld", sizeof(b)); NSLog(@"%ld", sizeof(p)); NSLog(@"%ld", sizeof(dd)); //dd是指向字符串常量的字符指针 NSLog(@"%ld", sizeof(*dd)); //*dd是第一个字符 (所占大小由数据类型决定) 答案: 32位机器上运行: 12 14 4 4 1 64位机器上运行: 12 14 8 8 1 运用2: NSLog(@"%lu,%lu,%lu,%lu",sizeof(char),sizeof(char*),sizeof(char[4]),sizeof((char*)(12))); NSLog(@"%lu,%lu,%lu,%lu",sizeof(char),sizeof(char*),sizeof(char[0]),sizeof((char*)(12))); 32位机器上运行: 1,4,4,4