004 C/C++ 数据类型_类型别名

 1 #include "stdio.h"
 2 #include "stdlib.h"
 3 
 4 //这里定义了一个结构体.
 5 struct MyStruct1
 6 {
 7     int a;
 8     float b;
 9 };
10 
11 // 这里定义了一个结构体和它的别名.
12 typedef struct MyStruct2
13 {
14     int a;
15     float b;
16 } MyStruct2;
17 
18 //定义简单数据类型的别名
19 typedef int u32;
20 
21 void main()
22 {
23     //MyStruct1 a;        //在c中这是错误的编译不通过. C++中对struct有增强可以这样写.
24     struct MyStruct1 a; //在C中正确写法.
25     MyStruct2 b;        
26     u32 c;
27     printf( "sizeof(a):%d, sizeof(b):%d, sizeof(c):%d \n", sizeof( a ), sizeof( b ), sizeof( c ) );
28     system( "pause" );
29 }

Output Result:

output result:
sizeof(a):8, sizeof(b):8, sizeof(c):4
请按任意键继续. . .

猜你喜欢

转载自www.cnblogs.com/it89/p/11069514.html