Govt. Exams
Entrance Exams
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.
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.
Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.
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?
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).
Option A correctly creates a static array of 100 structures. Option B creates a pointer (and allocates incorrect size).
Anonymous structures allow direct member access without needing to reference the nested structure name.
If B is embedded in A: a_var.b_var.member. If B is a pointer in A: a_var->b_var->member or a_var.b_ptr->member.
Structures can be passed by value (copying the entire structure) or by pointer (passing address) for efficiency.
C does not support direct comparison of structures using ==. You must compare members individually or use memcmp().
struct Flags {
unsigned int flag1 : 1;
unsigned int flag2 : 3;
unsigned int flag3 : 4;
};
What is the minimum size of this structure?
Bit fields must fit within an underlying integer type. Total bits = 8, which requires at least 4 bytes (one int on most systems).