C++中,struct和typedef struct的区别(代码展示)
1 #include<iostream> 2 3 using namespace std; 4 5 struct Date 6 { 7 int month; 8 int day; 9 int year; 10 }exam1; 11 12 typedef struct Date1 13 { 14 int c; 15 int x; 16 int z; 17 }exam2; 18 19 int main() 20 { 21 22 exam1.day = 1;//这里的exam1就是为结构体变量名(说白了,就是直接用) 23 24 exam2 s;//这里的exam2就是为结构体类型名(相当于int),所以还得定义一个变量s 25 s.c = 1; 26 27 cout<<exam1.day<<endl; 28 cout<<s.c<<endl; 29 30 return 0; 31 }