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 391–400 of 490
Topics in C Programming
Q.391 Medium Control Flow
Determine the output:
int i = 0;
while (i < 3) {
printf("%d ", i++);
}
A 0 1 2
B 1 2 3
C 0 1 2 3
D Infinite loop
Correct Answer:  A. 0 1 2
EXPLANATION

i starts at 0. Loop prints i then increments: prints 0, then 1, then 2. When i becomes 3, condition fails.

Test
Q.392 Medium Control Flow
What is the output?
int n = 1;
do {
printf("%d ", n);
n++;
} while (n > 5);
A 1
B 1 2 3 4 5
C No output
D Infinite loop
Correct Answer:  A. 1
EXPLANATION

The do-while executes once (prints 1), then n becomes 2. Since 2 > 5 is false, the loop exits.

Test
Q.393 Medium Control Flow
What is printed by this code?
int x = 5;
while (x-- > 0)
printf("%d ", x);
A 5 4 3 2 1 0
B 4 3 2 1 0
C 5 4 3 2 1
D 4 3 2 1
Correct Answer:  B. 4 3 2 1 0
EXPLANATION

x-- returns 5 first, then decrements to 4. Loop runs while x > 0, printing 4, 3, 2, 1, 0.

Test
Q.394 Medium Control Flow
How many times will this loop execute?
for (int i = 0; i < 5; ++i) {
if (i == 2) continue;
if (i == 4) break;
}
A 2 times
B 3 times
C 4 times
D 5 times
Correct Answer:  C. 4 times
EXPLANATION

Loop runs for i=0,1,2,3. When i=4, break is executed. The body executes 4 times (iterations for i=0,1,2,3).

Test
Q.395 Medium Control Flow
What is the output of this switch statement?
int x = 2;
switch(x) {
case 1: printf("One"); break;
case 2: printf("Two");
case 3: printf("Three"); break;
default: printf("Other");
}
A Two
B TwoThree
C Three
D TwoThreeOther
Correct Answer:  B. TwoThree
EXPLANATION

Case 2 matches. Since there's no break after case 2, fall-through occurs to case 3, printing 'TwoThree'.

Test
Q.396 Medium Control Flow
What does the following nested if-else produce?
int a = 10, b = 20;
if (a > b)
if (b > 0)
printf("X");
else
printf("Y");
A X
B Y
C XY
D No output
Correct Answer:  B. Y
EXPLANATION

The else clause pairs with the inner if. Since a > b is false, the else block executes printing 'Y'.

Test
Q.397 Medium Control Flow
What is the output?
for (int i = 1; i
A 1 2
B 1 2 3
C 1 2 3 4 5
D 2 3 4
Correct Answer:  A. 1 2
EXPLANATION

When i becomes 3, break is executed, exiting the loop. So only 1 and 2 are printed.

Test
Q.398 Medium Control Flow
What will be printed?
int x = 0;
if (x = 5)
printf("True");
else
printf("False");
A True
B False
C Compilation error
D Undefined behavior
Correct Answer:  A. True
EXPLANATION

x = 5 assigns 5 to x and evaluates to 5 (non-zero), which is true. So 'True' is printed.

Test
Consider a scenario where you need to store a variable that can hold values up to 10 billion. Which data type is most suitable?
A int
B long int
C long long int
D float
Correct Answer:  C. long long int
EXPLANATION

int max is ~2.1 billion, long int varies (may be 32 or 64 bits). long long int guarantees 64 bits with max ~9.2 quintillion, sufficient for 10 billion.

Test
What is the output of:
int arr[3] = {1, 2, 3};
int *p = arr;
printf("%d %d", *p, *(p+2));
A 1 3
B 1 2
C 3 3
D Garbage values
Correct Answer:  A. 1 3
EXPLANATION

p points to arr[0] which is 1. p+2 points to arr[2] which is 3. Therefore output is '1 3'.

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