Which of the following statements about structure initialization in C is INCORRECT?
ADesignated initializers allow setting members in any order
BAll members must be explicitly initialized during declaration
CMembers can be initialized during structure definition
DPartial initialization results in uninitialized members having indeterminate values
Correct Answer:
B. All members must be explicitly initialized during declaration
EXPLANATION
Members do not need to be explicitly initialized. Uninitialized members in automatic structures have indeterminate values, while static structures have zero-initialized members. Designated initializers (C99+) allow flexible initialization order.
In the context of bit fields in structures, what is the maximum number of bits that can be allocated to a single member in standard C?
A8 bits
B16 bits
CSize of the underlying type in bits
D32 bits
Correct Answer:
C. Size of the underlying type in bits
EXPLANATION
The maximum number of bits for a bit field member cannot exceed the size of the underlying type. For int (typically 32 bits), you can allocate up to 32 bits to a single member.
Which feature in C allows you to define a structure without a tag name for use within another structure?
ATagged union
BAnonymous structure
CTypedef structure
DNested enumeration
Correct Answer:
B. Anonymous structure
EXPLANATION
Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.
Consider the following code:
struct Data {
int x;
char y;
double z;
};
Assuming int=4 bytes, char=1 byte, double=8 bytes, what is the size of struct Data due to padding?
A13 bytes
B16 bytes
C20 bytes
D24 bytes
Correct Answer:
D. 24 bytes
EXPLANATION
Memory alignment causes padding. x(4) + padding(4) + y(1) + padding(7) + z(8) = 24 bytes. The compiler aligns to the largest member (double = 8 bytes).
Consider a structure with bit fields:
struct Flags {
unsigned int flag1 : 1;
unsigned int flag2 : 3;
unsigned int flag3 : 4;
};
What is the minimum size of this structure?
A1 byte
B2 bytes
C4 bytes
D8 bytes
Correct Answer:
C. 4 bytes
EXPLANATION
Bit fields must fit within an underlying integer type. Total bits = 8, which requires at least 4 bytes (one int on most systems).