基本数据类型
数据类型可以表示其在占用内存的大小,当一个数据类型定义了一个变量时,这个变量占用的内存大小与其数据类型一样。
1 #include<stdio.h> 2 3 int main() 4 { 5 char c = 'c'; 6 printf("sizeof(char)=%d,%d\n",sizeof(c),sizeof(char)); 7 8 int j=1; 9 printf("sizeof(int)=%d,%d\n",sizeof(j),sizeof(int)); 10 11 float f = 0.78; 12 printf("sizeof(float)=%d,%d\n",sizeof(f),sizeof(float)); 13 14 long l = 89; 15 printf("sizeof(long)=%d,%d\n",sizeof(l),sizeof(long)); 16 17 unsigned int t = 7; 18 printf("sizeof(unsigned int)=%d,%d\n",sizeof(t),sizeof(unsigned int)); 19 20 unsigned long k = 8; 21 printf("sizeof(unsigned long)=%d,%d\n",sizeof(k),sizeof(unsigned long)); 22 23 double d = 1.90; 24 printf("sizeof(double)=%d,%d\n",sizeof(d),sizeof(double)); 25 26 return 0; 27 }
1 #include<stdio.h> 2 3 typedef int INT32; 4 typedef unsigned char BYTE; 5 typedef struct _tag_TS 6 { 7 BYTE b1; 8 BYTE b2; 9 short s; 10 INT32 i; 11 }TS; 12 13 struct _tag_DT 14 { 15 double d; 16 float f; 17 }dt; 18 19 //typedef DT struct _tag_DT ; 20 21 int main() 22 { 23 INT32 i32; 24 BYTE b; 25 TS ts; 26 //struct DT dt; 27 28 printf("INT32=%d,%d\n",sizeof(INT32),sizeof(i32)); 29 printf("BYTE=%d,%d\n",sizeof(BYTE),sizeof(b)); 30 printf("TS=%d,%d\n",sizeof(TS),sizeof(ts)); 31 printf("_tag_DT=%d,%d\n",sizeof(_tag_DT),sizeof(dt)); 32 33 return 0; 34 }