Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
What is the size of the following structure?
struct point { int x; int y; float z; };
struct point { int x; int y; float z; };
Correct Answer:
B. 12 bytes
EXPLANATION
int x = 4 bytes, int y = 4 bytes, float z = 4 bytes. Total = 12 bytes (no padding in this case on most systems).
Which keyword is used to define a structure in C?
Correct Answer:
B. struct
EXPLANATION
The 'struct' keyword is used to define structures in C. 'class' is used in C++ and Java.
What will be the output of sizeof(union test) if union has members: int a, char b, float c?
Correct Answer:
A. 4 bytes
EXPLANATION
Union size equals the size of its largest member. Here, both int and float are 4 bytes (largest), so sizeof(union test) = 4 bytes.
What is the primary difference between a structure and a union in C?
Correct Answer:
A. Structure allocates memory for all members, union shares memory among members
EXPLANATION
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.