Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 191–200 of 490
Topics in C Programming
Q.191 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.

Test
Q.192 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.

Test
Q.193 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).

Test
Q.194 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.

Test
Q.195 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.

Test
Q.196 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.

Test
Q.197 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'.

Test
Q.198 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.

Test
Q.199 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.

Test
Q.200 Medium Pointers
Consider a function void modify(int *x) { *x = 20; } called as modify(&y). What happens?
A y is passed by value; changes don't affect original y
B Address of y is passed; changes inside modify affect original y
C y is copied to a temporary variable
D The function cannot access y
Correct Answer:  B. Address of y is passed; changes inside modify affect original y
EXPLANATION

When &y is passed to a function expecting a pointer parameter, the address is passed. Changes via pointer dereference affect the original variable.

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