计算结构体变量所占的存储单元
#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;
}
网友评论