Decision Control & Loops Question Bank for C-CAT
Topic-wise Decision Control & Loops MCQs for CDAC C-CAT preparation with answers and explanations.
What will be the output?
int x = 5;
if(x = 0)
printf("Yes");
else
printf("No");Show Answer & Explanation
Correct Answer: A - No
Assignment x=0 makes condition false, so else block executes.
Show Answer & Explanation
Correct Answer: D - Expression
Switch must have an expression to evaluate.
What will be the output?
int x = 3;
if(x > 5)
printf("A");
else if(x > 2)
printf("B");
else
printf("C");Show Answer & Explanation
Correct Answer: A - B
x > 2 is true, so B is printed.
Show Answer & Explanation
Correct Answer: C - do-while
do-while checks condition after executing loop body.
What will be the output?
int i;
for(i=0;i<3;i++);
printf("%d", i);Show Answer & Explanation
Correct Answer: D - 3
Semicolon makes loop body empty; loop runs fully.
Show Answer & Explanation
Correct Answer: B - continue
continue skips remaining statements of current iteration.
What will be the output?
int i=1;
while(i<=5)
{
if(i==3) break;
printf("%d", i);
i++;
}Show Answer & Explanation
Correct Answer: B - 12
Loop breaks when i becomes 3.
Show Answer & Explanation
Correct Answer: D - Works with int/char
switch supports integral constant expressions.
What will be the output?
int i=0;
do
{
printf("%d", i);
i++;
}while(i<0);Show Answer & Explanation
Correct Answer: B - 0
do-while executes once before checking condition.
Show Answer & Explanation
Correct Answer: D - for
for loop is preferred when iteration count is known.
What will be the output?
int i;
for(i=1;i<=5;i++)
{
if(i==4) continue;
printf("%d", i);
}Show Answer & Explanation
Correct Answer: A - 1235
continue skips printing when i=4.
Show Answer & Explanation
Correct Answer: C - if a>b
Condition must be inside parentheses.
What will be the output?
int i=5;
while(i--)
printf("%d", i);Show Answer & Explanation
Correct Answer: A - 43210
Post-decrement evaluates then decrements.
Show Answer & Explanation
Correct Answer: C - goto
goto jumps unconditionally to labeled statement.
What will be the output?
int x=1;
switch(x)
{
case 1: printf("A");
case 2: printf("B");
default: printf("C");
}Show Answer & Explanation
Correct Answer: B - ABC
Without break, execution falls through all cases.
Show Answer & Explanation
Correct Answer: B - Both for and while
Both test condition before entering loop body.
What will be the output?
int i=0;
for(;i<3;)
{
printf("%d", i);
i++;
}Show Answer & Explanation
Correct Answer: C - 012
All expressions in for loop are optional.
Show Answer & Explanation
Correct Answer: A - Exits loop/switch
break exits nearest loop or switch.
What will be the output?
int i=1;
while(i<=3)
{
printf("%d", i++);
}Show Answer & Explanation
Correct Answer: D - 123
Post-increment prints then increments.
Show Answer & Explanation
Correct Answer: C - All can be used
Assignment in condition is allowed but risky.
What will be the output?
int i=0;
while(i<3)
printf("%d", i++);Show Answer & Explanation
Correct Answer: D - 012
i increments after printing.
Show Answer & Explanation
Correct Answer: C - All
All represent infinite loops.
What will be the output?
int x=2;
if(x==2)
printf("A");
else
printf("B");Show Answer & Explanation
Correct Answer: B - A
x==2 is true, so A is printed.
Show Answer & Explanation
Correct Answer: D - return
return transfers control back to caller.
What will be the output?
int i;
for(i=0;i<5;i++)
{
if(i==2) break;
printf("%d", i);
}Show Answer & Explanation
Correct Answer: D - 01
Loop breaks when i equals 2.
Show Answer & Explanation
Correct Answer: A - int/char
Only integral types allowed.
What will be the output?
int i=1;
do
{
printf("%d", i);
i++;
}while(i<=3);Show Answer & Explanation
Correct Answer: D - 123
do-while prints before checking condition.
Show Answer & Explanation
Correct Answer: B - Both for and while
Condition checked before entering loop.
What will be the output?
int x=0;
if(!x)
printf("True");Show Answer & Explanation
Correct Answer: C - True
!0 evaluates to true.
Show Answer & Explanation
Correct Answer: B - All
All are valid inside switch (context dependent).
What will be the output?
int i;
for(i=5;i>0;i--)
printf("%d", i);Show Answer & Explanation
Correct Answer: A - 54321
Loop decrements and prints.
Show Answer & Explanation
Correct Answer: C - if
if is a decision statement.
What will be the output?
int i=0;
while(++i < 4)
printf("%d", i);Show Answer & Explanation
Correct Answer: B - 123
Pre-increment increments before comparison.
Show Answer & Explanation
Correct Answer: C - continue
continue skips to next iteration.
What will be the output?
int i=1;
for(;;)
{
if(i>3) break;
printf("%d", i);
i++;
}Show Answer & Explanation
Correct Answer: B - 123
Loop breaks explicitly.
Show Answer & Explanation
Correct Answer: A - default is optional
default case is optional.
What will be the output?
int x=5;
if(x--)
printf("A");Show Answer & Explanation
Correct Answer: C - A
Post-decrement evaluates before decrement.
Show Answer & Explanation
Correct Answer: A - All
All control statements can be nested.
What will be the output?
int i=0;
do
{
i++;
}while(i<3);
printf("%d", i);Show Answer & Explanation
Correct Answer: B - 3
Loop runs until i reaches 3.
Show Answer & Explanation
Correct Answer: D - break
break exits nearest loop or switch.
What is the output of this code?
for(int i = 0; i < 5; i++) {
if(i == 3) continue;
printf("%d ", i);
}Show Answer & Explanation
Correct Answer: B - 0 1 2 4
The 'continue' statement skips the rest of the current iteration and moves to the next iteration. When i equals 3, the printf is skipped, so the output is 0 1 2 4.
What will be printed?
int x = 2;
switch(x) {
case 1: printf("One ");
case 2: printf("Two ");
case 3: printf("Three ");
default: printf("Default");
}Show Answer & Explanation
Correct Answer: A - Two Three Default
Without 'break' statements, switch cases fall through. When x matches case 2, execution continues through case 3 and default. This prints 'Two Three Default'. Break statements are needed to prevent fall-through behavior.
How many times will 'Hello' be printed?
int i = 0;
do {
printf("Hello\n");
i++;
} while(i < 0);Show Answer & Explanation
Correct Answer: D - 1 time
A do-while loop always executes its body at least once before checking the condition. The body prints 'Hello' and increments i to 1. Then the condition (1 < 0) is false, so the loop exits. Output: Hello is printed exactly once.
What is the output?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(j == 2) break;
printf("%d%d ", i, j);
}
}Show Answer & Explanation
Correct Answer: A - 11 21 31
The inner 'break' only breaks the inner loop when j equals 2. So for each value of i, only j=1 gets printed before break is hit. This gives 11 21 31.
What will this code output?
int n = 15;
if(n % 3 == 0 && n % 5 == 0)
printf("FizzBuzz");
else if(n % 3 == 0)
printf("Fizz");
else if(n % 5 == 0)
printf("Buzz");
else
printf("%d", n);Show Answer & Explanation
Correct Answer: C - FizzBuzz
15 is divisible by both 3 (15/3=5) and 5 (15/5=3). The first condition checks both using &&, and since both are true, 'FizzBuzz' is printed. The remaining else-if blocks are skipped.
What is the output?
int i;
for(i = 0; i < 10; i++) {
if(i * i > 20) break;
}
printf("%d", i);Show Answer & Explanation
Correct Answer: A - 5
The loop checks if i*i > 20. When i=0: 0>20 false. i=1: 1>20 false. i=2: 4>20 false. i=3: 9>20 false. i=4: 16>20 false. i=5: 25>20 true → break. After break, i is 5, which is printed.
What happens when the following code is compiled and run?
int x = 0;
while(x);
printf("Executed");Show Answer & Explanation
Correct Answer: C - "Executed" is printed once
The semicolon after while(x) makes it an empty while loop body. Since x is 0, the while condition is false and the empty loop doesn't execute at all. The printf statement is not part of the loop — it's a separate statement that always executes. So 'Executed' is printed once.
What is the output of this nested loop?
int count = 0;
for(int i = 0; i < 4; i++) {
for(int j = i; j < 4; j++) {
count++;
}
}
printf("%d", count);Show Answer & Explanation
Correct Answer: A - 10
When i=0, j goes 0,1,2,3 → 4 iterations. When i=1, j goes 1,2,3 → 3 iterations. When i=2, j goes 2,3 → 2 iterations. When i=3, j goes 3 → 1 iteration. Total: 4+3+2+1 = 10.
What is the output?
int val = 3;
switch(val) {
case 1 ... 3:
printf("Low");
break;
case 4 ... 6:
printf("Mid");
break;
default:
printf("High");
}Show Answer & Explanation
Correct Answer: D - Compilation error (standard C does not support range in case)
The case range syntax (case 1 ... 3) is a GCC extension and is not part of the standard C language. In strict standard C compilation, this will produce a compilation error. Standard C requires individual case labels for each value.
What is the value of sum after this code executes?
int sum = 0;
for(int i = 1; i <= 100; i++) {
if(i % 2 != 0) continue;
sum += i;
}
printf("%d", sum);Show Answer & Explanation
Correct Answer: B - 2550
The continue statement skips odd numbers (when i%2 != 0). So only even numbers from 2 to 100 are summed. The sum of even numbers from 2 to 100 is 2+4+6+...+100 = 2(1+2+3+...+50) = 2 × (50×51)/2 = 2550.