Govt. Exams
Entrance Exams
A structure allows grouping of different data types. Padding may be added by the compiler for alignment.
Structures must be initialized at declaration time using curly braces. Assignment of initializer list is not valid after declaration.
The correct syntax for typedef struct is: typedef struct { members } StructName;
The arrow operator (->) is used to access structure members through a pointer. The dot operator is used with direct variables.
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 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.
In C, self-referential structures require the struct keyword in pointer declarations within the structure definition.
Both methods are valid - A uses named struct tag with variable declaration, C uses anonymous struct with variable declaration.