Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 191–200 of 499
Topics in C Programming
Q.191 Medium Structures & Unions
In a nested structure, how do you access the innermost member? struct outer { struct inner { int value; } in; } obj;
A obj.value
B obj.in.value
C obj->in->value
D obj.in->value
Correct Answer:  B. obj.in.value
EXPLANATION

For nested structures accessed through an object, use the dot operator multiple times: obj.in.value accesses the value member of the inner structure.

Take Test
Q.192 Medium Structures & Unions
What will be printed by this code? struct s { int a; struct s *next; }; struct s *ptr; sizeof(struct s)
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  C. 12 bytes
EXPLANATION

sizeof(int) = 4 bytes, sizeof(pointer) = 8 bytes (on 64-bit systems). Total = 12 bytes. Pointers are fixed size regardless of what they point to.

Take Test
Q.193 Medium Structures & Unions
Consider struct test { int x; double y; char z; }; What is the minimum size of this structure (assuming 4-byte int, 8-byte double)?
A 13 bytes
B 16 bytes
C 20 bytes
D 24 bytes
Correct Answer:  D. 24 bytes
EXPLANATION

Due to padding: int (4) + padding (4) + double (8) + char (1) + padding (3) = 24 bytes. The structure aligns to the largest member size.

Take Test
Q.194 Medium Structures & Unions
Consider: union u { int x; double y; }; What is sizeof(u)?
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

The size of a union is equal to its largest member. double is typically 8 bytes, which is larger than int (4 bytes).

Take Test
Q.195 Medium Structures & Unions
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.

Take Test
Q.196 Medium Structures & Unions
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.

Take Test
Q.197 Medium Structures & Unions
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.

Take Test
Q.198 Medium Structures & Unions
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'.

Take Test
Q.199 Medium Structures & Unions
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.

Take Test
Q.200 Medium Structures & Unions
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.

Take Test
IGET
iget AI
Online · Ask anything about exams
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