Home Subjects C Programming Structures & Unions

C Programming
Structures & Unions

C language from basics to advanced placement prep

46 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–46 of 46
Topics in C Programming
What is the purpose of padding in structures?
A To waste memory intentionally
B To align data for faster CPU access
C To prevent hacking
D To increase security
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.

Test
How do you access a member of a structure using a pointer?
A ptr.member
B ptr->member
C *ptr.member
D ptr*member
Correct Answer:  B. ptr->member
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. Dot (.) is for direct variables.

Test
What will be printed?
struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
A 9 bytes
B 12 bytes
C 13 bytes
D 8 bytes
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.

Test
What is the difference between struct and typedef struct?
A No difference, both are identical
B typedef struct allows direct variable declaration without 'struct' keyword
C struct is faster than typedef struct
D typedef struct is used only in C++
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'.

Test
Which of the following correctly declares a pointer to a structure?
A struct emp *ptr;
B *struct emp ptr;
C struct *emp ptr;
D emp struct *ptr;
Correct Answer:  A. struct emp *ptr;
EXPLANATION

Correct syntax is 'struct typename *pointerName;'. Option A follows proper declaration syntax.

Test
What happens when you initialize a structure variable without assigning values?
A Members are automatically set to 0
B Members contain garbage values
C Compilation error occurs
D Members are set to NULL
Correct Answer:  B. Members contain garbage values
EXPLANATION

Uninitialized local structure variables contain garbage values. Global structures are automatically initialized to zero.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips