Exercise: Structures Unions Enums

Questions for: Structures Unions Enums

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;
};
A:
Yes
B:
No
C:
D:
Answer: 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.
Can a structure can point to itself?
A:
Yes
B:
No
C:
D:
Answer: A
A structure pointing to itself is called self-referential structures.
Will the following declaration work?
typedef struct s
{
    int a;
    float b;
}s;
A:
Yes
B:
No
C:
D:
Answer: A
No answer description is available. Let's discuss.
Can we have an array of bit fields?
A:
Yes
B:
No
C:
D:
Answer: B
No answer description is available. Let's discuss.
Is it necessary that the size of all elements in a union should be same?
A:
Yes
B:
No
C:
D:
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz