Sail E0 Webinar
Question


If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide
then will the following structure always occupy 7 bytes?


struct ex
{
char ch;
int i;
long int a;
};
Options:
A .  Yes
B .  No
Answer: Option B

A compiler may leave holes in structures by padding the first char in the structure with another 

byte just to ensures that the integer that follows is stored at an location. Also, there might be 

2extra bytes after the integer to ensure that the long integer is stored at an address, which is 

multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers