结构体例题1

2018-09-17  本文已影响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;
}

上一篇下一篇

猜你喜欢

热点阅读