Entrance Exams
Govt. Exams
The arrow operator (->) is used to access structure members through a pointer. Dot (.) is for direct variables.
struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
Due to memory alignment/padding: int a(4) + char b(1) + 3 padding bytes + int c(4) = 12 bytes.
typedef struct creates an alias, so you can declare variables directly using the alias name without repeating 'struct'.
Correct syntax is 'struct typename *pointerName;'. Option A follows proper declaration syntax.
Uninitialized local structure variables contain garbage values. Global structures are automatically initialized to zero.
Structures can be passed by value (copy of structure) or by reference (using pointers to structure).
struct point { int x; int y; float z; };
int x = 4 bytes, int y = 4 bytes, float z = 4 bytes. Total = 12 bytes (no padding in this case on most systems).
The 'struct' keyword is used to define structures in C. 'class' is used in C++ and Java.
Union size equals the size of its largest member. Here, both int and float are 4 bytes (largest), so sizeof(union test) = 4 bytes.
In structures, each member gets its own memory space. In unions, all members share the same memory location, so only one member can hold a value at a time.