Entrance Exams
Govt. Exams
Bit field allocation order (left-to-right or right-to-left) varies across compilers, affecting portability.
union Data { int x; char y; };
Data d = {65};
d.y = 'A';
printf("%d", d.x);
Modifying y changes the same memory location as x. Only the last byte of x is affected, leading to unpredictable output.
Passing by pointer avoids copying the entire structure, making it efficient for large data structures.
struct Data { char c; int i; short s; };
Due to padding/alignment: char(1) + padding(3) + int(4) + short(2) = 12 bytes on 32-bit systems.
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.