Govt. Exams
Entrance Exams
struct S { int a:3; int b:3; int c:3; };
printf("%zu", sizeof(struct S));
Bit field packing is implementation-defined. Size depends on compiler's bit field allocation strategy.
struct FlexArray { int len; int arr[]; };
Flexible array members require dynamic allocation; the structure itself cannot be allocated on the stack with a defined size for the array.
Compilers add padding bytes between structure members to align them on boundaries (usually power of 2), improving memory access performance on the target architecture.
Both o->ptr->x and (*o).ptr->x are equivalent. Arrow operator can chain for pointers, and (*pointer).member is equivalent to pointer->member.
Bit fields can pack 8 flags per byte, so 100 flags need ~13 bytes. Char array needs 100 bytes. Bit fields are more memory-efficient for flag storage.
Since union members share memory, setting y[0]=65 and y[1]=66 overwrites the int x value. The exact value depends on endianness.
Self-referential structures contain pointers to the same structure type (like linked list nodes). Recursion refers to function calls, not structures.
Both {0} and {} will initialize all members to zero. These are equivalent in C99 and later standards.
struct u { int a; char b; }; u.a = 257; printf("%d", u.b);
In a union, both members share memory. 257 in binary is 100000001. u.b (char) reads only the LSB, which is 1.
C allows structures to have other structures as members. This is called nested structures and is a common practice.