gmmargin 2012-12-24
可用如sizeof(char),sizeof(char*)等得出
32位编译器
char :1个字节
char*(即指针变量): 4个字节(32位的寻址空间是2^32,即32个bit,也就是4个字节。同理64位编译器)
short int : 2个字节
int: 4个字节
unsigned int : 4个字节
float: 4个字节
double: 8个字节
long: 4个字节
long long: 8个字节
unsigned long: 4个字节
64位编译器
char :1个字节
char*(即指针变量): 8个字节
short int : 2个字节
int: 4个字节
unsigned int : 4个字节
float: 4个字节
double: 8个字节
long: 8个字节
long long: 8个字节
unsigned long: 8个字节
#import <Foundation/Foundation.h>
struct {
short a1;
short a2;
short a3;
}A;
struct {
long long a1;
short a2;
}B;
int main (int argc, const char * argv[])
{
@autoreleasepool {
char *ss1="0123456789";
char ss2[]="0123456789";
char ss3[100]="0123456789";
int ss4[100];
char q1[]="abc";
char q2="a\n";
char *q3="a\n";
char *str1=(char *)malloc(100);
void *str2=(void *)malloc(100);
NSLog(@"%lu",sizeof(ss1));//8
NSLog(@"%lu",sizeof(ss2));//11
NSLog(@"%lu",sizeof(ss3));//100
NSLog(@"%lu",sizeof(ss4));//400
NSLog(@"%lu",sizeof(q1));//4
NSLog(@"%lu",sizeof(q2));//1
NSLog(@"%lu",sizeof(q3));//8
NSLog(@"%lu",sizeof(str1));//8
NSLog(@"%lu",sizeof(str2));//8
NSLog(@"%lu",sizeof(A));//6
NSLog(@"%lu",sizeof(B));//16
}
return 0;
}