Govt. Exams
Entrance Exams
typedef creates an alias for the struct type, allowing direct use without 'struct' keyword.
struct Point { int x; int y; };
struct Point p = {5};
printf("%d %d", p.x, p.y);
When initializing a struct with fewer values than members, remaining members are zero-initialized. p.x=5, p.y=0.
Structures allow you to combine multiple data types into a single composite type, making code organization and data management more efficient.
The arrow operator (->) is used to access structure members through a pointer. It dereferences the pointer and accesses the member in one operation.
Padding adds unused bytes between members to align them on word boundaries, improving CPU access efficiency and performance.
The typedef keyword creates an alias for a data type, allowing you to use a shorter name instead of the full struct declaration.
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.
Structures can be passed by value (copy of structure) or by reference (using pointers to structure).