qt开发环境

来源:互联网 发布:网络用语dw什么意思 编辑:程序博客网 时间:2024/06/07 15:12
#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;//16    cout << "sizeof(user) = " << sizeof(user) << endl;//16    cout << "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();}

原创粉丝点击