Entrance Exams
Govt. Exams
The arrow operator (->) is used to access structure members through a pointer. The dot operator is used with direct variables.
Self-referential pointers (a structure containing a pointer to itself) are essential for creating linked list nodes.
The size of a union equals the size of its largest member. Here, int is 4 bytes (largest), so union size is 4 bytes.
Union members share the same memory location, and the union size equals the size of its largest member.
struct Point { char c; int x; };
Due to structure padding/alignment, char (1 byte) + 3 bytes padding + int (4 bytes) = 8 bytes total.
struct X { int a; float b; };
struct Y { struct X x; int c; };
printf("%zu", sizeof(struct Y));
Nested struct X: int(4) + float(4) = 8 bytes. Y: struct X(8) + padding(0) + int(4) = 12, but with overall alignment it becomes 16 bytes.
Unions are optimal for memory-constrained scenarios and hardware programming where type casting is needed.
struct Student { int roll; char name[50]; };
Correct allocation requires pointer declaration, proper cast, and multiplying n with sizeof(struct Student).
Pass by value creates a complete copy of the structure on the function's stack frame.
Unions enable type punning and efficient hardware register representation where different interpretations of same memory are needed.