+ 2
C++ - Size of a struct
Why is output 12? #include <iostream> using namespace std; struct student{ char a; int c; char b; }; int main() { cout << sizeof(student); return 0; }
3 Respuestas
+ 4
A good explanation is here:
https://www.geeksforgeeks.org/is-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member/amp/
+ 2
Very clear, thank you!
0
Because char is considered to be 4 bytes in a struct.
it is 1 byte but 3 bytes are added to satisfy alignment constraints.