Expedia Interview Question
SDE-2sTeam: LSB
Country: United States
Interview Type: Phone Interview
A struct is a value type so it is stored on the stack, but class is a reference type so it is stored in a heap.A structure can't support inheritance and polymorphism, but class support both. By default struct are public in nature but class are private in nature.
Padding :- In order to align the memory one or more empty bytes (addresses) are inserted between memory addresses. which are allocated for other structure member while memory allocation.This concept is called structure padding.
Padding added to have better memory alignment for faster memory access.
On 64-bit systems, pointers are 8 bytes. Compilers will align structure members to natural boundaries, so an 8-byte pointer will start at an offset in a structure that is a multiple of 8 bytes.
- rahul thakur July 12, 2014Since int is only four bytes, the compiler inserted 4 bytes of "padding" after foo, so that smap is on an 8-byte boundary.