Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
What is the purpose of padding in structures?
Correct Answer:
B. To align data for faster CPU access
EXPLANATION
Padding ensures that structure members are aligned in memory according to their natural boundaries, improving CPU access speed.
How do you access a member of a structure using a pointer?
Correct Answer:
B. ptr->member
EXPLANATION
The arrow operator (->) is used to access structure members through a pointer. Dot (.) is for direct variables.
What will be printed?
struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
Correct Answer:
B. 12 bytes
EXPLANATION
Due to memory alignment/padding: int a(4) + char b(1) + 3 padding bytes + int c(4) = 12 bytes.
What is the difference between struct and typedef struct?
Correct Answer:
B. typedef struct allows direct variable declaration without 'struct' keyword
EXPLANATION
typedef struct creates an alias, so you can declare variables directly using the alias name without repeating 'struct'.
Which of the following correctly declares a pointer to a structure?
Correct Answer:
A. struct emp *ptr;
EXPLANATION
Correct syntax is 'struct typename *pointerName;'. Option A follows proper declaration syntax.
What happens when you initialize a structure variable without assigning values?
Correct Answer:
B. Members contain garbage values
EXPLANATION
Uninitialized local structure variables contain garbage values. Global structures are automatically initialized to zero.