-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsizeofStruct.cpp
More file actions
50 lines (44 loc) · 764 Bytes
/
sizeofStruct.cpp
File metadata and controls
50 lines (44 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;
struct A{
int a;
double b;
char c;
};
struct B{
double b;
char c;
int a;
};
struct C{
int a;
char c;
double b;
};
struct D
{
char a;
double b;
int c;
char d;
};
struct E
{
char a;
struct D d;
int c;
};
int main(){
/* Ref: https://www.twblogs.net/a/5b8cad052b71771883347a35 */
A aa;
B bb;
C cc;
D dd;
E ee;
cout << "A struct size: " << sizeof(aa) << endl; // 24
cout << "B struct size: " << sizeof(bb) << endl; // 16
cout << "C struct size: " << sizeof(cc) << endl; // 16
cout << "D struct size: " << sizeof(dd) << endl; // 24
cout << "E struct size: " << sizeof(ee) << endl; // 40
return 0;
}