美文网首页
结构体例题1

结构体例题1

作者: 这么帅的人啊 | 来源:发表于2018-09-17 22:11 被阅读0次

    计算结构体变量所占的存储单元

    #include<iostream>
    using namespace std;
    int main()
    {
        char str[20];
        struct date
        {
            int year,month,day;
        }today;
        struct address
        {
            char name[30],street[40],city[20],state[2];
            unsigned long int zip;
        }wang;
        cout<<"char:"<<sizeof(char)<<"\t";
        cout<<"int:"<<sizeof(int)<<"\t";
        cout<<"long:"<<sizeof(long)<<"\t";
        cout<<"float:"<<sizeof(float)<<"\t";
        cout<<"double:"<<sizeof(double)<<"\t";
        cout<<"str:"<<sizeof(str)<<"\t";
        cout<<"date:"<<sizeof(date)<<"\t";
        cout<<"wang:"<<sizeof(wang)<<"\t";
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:结构体例题1

          本文链接:https://www.haomeiwen.com/subject/mxqjnftx.html