#include<iostream>
using namespace std;
int main()
{
struct s1
{
char mark;
long num;
float score;
}s1;
union s2
{
char mark;
long num;
float score;
}s2;
cout << sizeof(s1.mark) << endl;
cout << sizeof(s1.num) << endl;
cout << sizeof(s1.score) << endl;
cout << sizeof(s1) << endl;
cout << "------------" << endl;
cout << sizeof(s2.mark) << endl;
cout << sizeof(s2.num ) << endl;
cout << sizeof(s2.score) << endl;
cout << sizeof(s2) << endl;
}
输出
1
4
4
12
------------
1
4
4
4
H:\Project47\Debug\Project47.exe (进程 17036)已退出,返回代码为: 0。
若要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口...
参考:https://www.cnblogs.com/jeakeven/p/5113508.html