Practice 40 Decision Control & Loops multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
What will be the output?
int x = 5;
if(x = 0)
printf("Yes");
else
printf("No");Show Answer & Explanation
Correct Answer: B — 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: B — 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: C — 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: C — 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: C — 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: B — 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: C — ABC
Without break, execution falls through all cases.
Show Answer & Explanation
Correct Answer: D — 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: A — 012
All expressions in for loop are optional.
Show Answer & Explanation
Correct Answer: C — 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: A — 123
Post-increment prints then increments.
Show Answer & Explanation
Correct Answer: D — 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: A — 012
i increments after printing.
Show Answer & Explanation
Correct Answer: D — 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: A — A
x==2 is true, so A is printed.
Show Answer & Explanation
Correct Answer: C — 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: B — 01
Loop breaks when i equals 2.
Show Answer & Explanation
Correct Answer: C — 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: A — 123
do-while prints before checking condition.
Show Answer & Explanation
Correct Answer: D — 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: A — True
!0 evaluates to true.
Show Answer & Explanation
Correct Answer: D — 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: A — 123
Pre-increment increments before comparison.
Show Answer & Explanation
Correct Answer: B — 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: A — 123
Loop breaks explicitly.
Show Answer & Explanation
Correct Answer: C — default is optional
default case is optional.
What will be the output?
int x=5;
if(x--)
printf("A");Show Answer & Explanation
Correct Answer: A — A
Post-decrement evaluates before decrement.
Show Answer & Explanation
Correct Answer: D — 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: C — break
break exits nearest loop or switch.