A struct is a datatype that composes a fixed set of labelled fields or members.
[In C++, the only difference between a struct and a class is the default access level, which is private for classes and public for structs.]
sizeof() returns the size in bytes.
The compiler inserts (padding) unused memory (extra bytes) into a 'struct' so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.
Example code: here
Output
sizeof(int): 4
sizeof(char): 1
sizeof(item): 8
[In C++, the only difference between a struct and a class is the default access level, which is private for classes and public for structs.]
sizeof() returns the size in bytes.
The compiler inserts (padding) unused memory (extra bytes) into a 'struct' so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.
Example code: here
Output
sizeof(int): 4
sizeof(char): 1
sizeof(item): 8
No comments:
Post a Comment