Govt Exams
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).
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.
int *p;
*p = 10;
p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.
Which statement is TRUE?
const int *p means p can change but the data it points to cannot. int * const q means q cannot change but the data it points to can be modified.
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
q is a pointer to pointer p. **q dereferences q twice: first to get p, then to get the value of x which is 10.