Question
struct ex
{
char ch;
int i;
long int a;
};
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;
};
Answer: Option B
Was this answer helpful ?
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 ?
More Questions on This Topic :
Question 1.
Can a structure can point to itself?
....
Question 3.
Can we have an array of bit fields?
....
Question 7.
A pointer union CANNOT be created
....
Submit Solution