定义结构体如下:
struct student
{
int iNum;
char *cName;
char cSex;
int iAge;
}
int main()
{
student sStu1;
sStu1.iNum = 97001;
sStu1.cName = "Wen Tian Xiang I am student";
sStu1.cSex = 'F';
sStu1.iAge = 19;
cout <<"sStu1.cName" << ends << sizeof(sStu1.cName) << endl;
cout <<"sStu1.iNum" << ends << sizeof(sStu1.iNum) << endl;
cout <<"sStu1.iAge" << ends << sizeof(sStu1.iAge) << endl;
cout <<"sStu1.cSex" << ends << sizeof(sStu1.cSex) << endl;
cout << "student" << ends << sizeof(student) <<endl;
return 0;
}
运行结果:
sStu1.cName 4
sStu1.iNum 4
sStu1.iAge 4
sStu1.cSex 1
student 16
问题:1\不是说结构体的内存大小是各数据成员的大小的和吗?那和为13,那怎么student的大小为16?
2\char *cName的大小为什么是4呢?
谢谢!!
[此贴子已经被作者于2007-5-23 21:43:28编辑过]