基本数据类型

 数据类型可以表示其在占用内存的大小,当一个数据类型定义了一个变量时,这个变量占用的内存大小与其数据类型一样。

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     char c = 'c';
 6     printf("sizeof(char)=%d,%d
",sizeof(c),sizeof(char));
 7 
 8     int j=1;
 9     printf("sizeof(int)=%d,%d
",sizeof(j),sizeof(int));
10 
11     float f = 0.78;
12     printf("sizeof(float)=%d,%d
",sizeof(f),sizeof(float));
13 
14     long l = 89;
15     printf("sizeof(long)=%d,%d
",sizeof(l),sizeof(long));
16 
17     unsigned int t = 7;
18     printf("sizeof(unsigned int)=%d,%d
",sizeof(t),sizeof(unsigned int));
19 
20     unsigned long k = 8;
21     printf("sizeof(unsigned long)=%d,%d
",sizeof(k),sizeof(unsigned long));
22 
23     double d = 1.90;
24     printf("sizeof(double)=%d,%d
",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
",sizeof(INT32),sizeof(i32));
29     printf("BYTE=%d,%d
",sizeof(BYTE),sizeof(b));
30     printf("TS=%d,%d
",sizeof(TS),sizeof(ts));
31     printf("_tag_DT=%d,%d
",sizeof(_tag_DT),sizeof(dt));
32 
33     return 0;
34 }

原文地址:https://www.cnblogs.com/zhulinhaibao/p/10322923.html