Govt. Exams
Entrance Exams
Designated initializers (C99) allow specifying members by name using dot notation, making code more readable and maintainable.
ptr points to obj, so ptr->a = 10 modifies obj.a to 10. The printf outputs the modified value 10.
In 'struct person { int age; } p;', 'person' is the tag (structure name) and 'p' is the type/variable. Tag names the structure template; type creates actual instances.
Bit fields allow you to specify the number of bits for integral members, enabling memory optimization by packing multiple small values into a single byte.
Since union members share memory, modifying one member overwrites the value of other members because they occupy the same memory location.
Structure arrays are initialized with nested braces, where each set of braces contains initialization values for one structure element.
For nested structures accessed through an object, use the dot operator multiple times: obj.in.value accesses the value member of the inner structure.
sizeof(int) = 4 bytes, sizeof(pointer) = 8 bytes (on 64-bit systems). Total = 12 bytes. Pointers are fixed size regardless of what they point to.
Due to padding: int (4) + padding (4) + double (8) + char (1) + padding (3) = 24 bytes. The structure aligns to the largest member size.
The size of a union is equal to its largest member. double is typically 8 bytes, which is larger than int (4 bytes).