#include <QCoreApplication>
#include <iostream>
using namespace std;
struct User {char name[12];int age;void who(void){cout << name << ", " << age <<endl;//注意此函数在代码区,sizeof结构体 不包括函数}
};int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);//结构/*struct*/User user = {"ayu",33}, user2 = {"mai",32}, *pUser = &user;cout << user.name << ", " << user.age <<endl;user.who();cout << pUser->name << ", " << pUser->age <<endl;pUser->who();pUser = &user2;cout << pUser->name << ", " << pUser->age <<endl;pUser->who();cout << "sizeof(User) = " << sizeof(User) << endl;//16cout << "sizeof(user) = " << sizeof(user) << endl;//16cout << "sizeof(user2) = " << sizeof(user2) << endl;//16//联合union {//匿名联合
int n;char c[sizeof(n)];};n = 0x12345678;cout << hex << showbase << (int)c[0] << " " << (int)c[1] << " " << (int) c[2] << " " << (int)c[3] << endl;//枚举,c啪啪中枚举是独立的类型,不同于c语言里枚举就是整形//枚举范围小,整形范围大,所以枚举可以转为整形,反之不可return a.exec();
}