Entrance Exams
Govt. Exams
struct S { char c; int i; } s;
printf("%lu", sizeof(s));
char(1 byte) + padding(3 bytes) + int(4 bytes) = 8 bytes due to alignment requirements.
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.
Self-referential structures contain pointers to their own type, enabling dynamic data structures like linked lists and trees.
A self-referential structure with a single pointer member is the fundamental building block of a singly linked list.
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).
typedef creates an alias, allowing you to use the structure name directly without using 'struct' keyword.