Govt Exams
A self-referential structure contains a pointer to its own type, commonly used in creating linked lists, trees, and other data structures.
The size of a union is the size of its largest member. Here, double (8 bytes) is the largest, so sizeof(union data) = 8 bytes.
In unions, all members share the same memory location, so only one member can hold a value at a time. In structs, each member has its own memory space.
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.
The size of a union is equal to its largest member. double is typically 8 bytes, which is larger than int (4 bytes).
Padding ensures that structure members are aligned in memory according to their natural boundaries, improving CPU access speed.