C Programming

Decision Control & Loops — Practice MCQs for CCAT

40 Questions Section B: Programming C Programming

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.

Q1.

What will be the output?


int x = 5;
if(x = 0)
  printf("Yes");
else
  printf("No");
AYes
BNo
CCompilation error
DUndefined
Show Answer & Explanation

Correct Answer: B — No

Assignment x=0 makes condition false, so else block executes.

Q2.
Which of the following is mandatory in a switch statement?
Abreak
Bdefault
Ccase
DExpression
Show Answer & Explanation

Correct Answer: D — Expression

Switch must have an expression to evaluate.

Q3.

What will be the output?


int x = 3;
if(x > 5)
  printf("A");
else if(x > 2)
  printf("B");
else
  printf("C");
AA
BB
CC
DNo output
Show Answer & Explanation

Correct Answer: B — B

x > 2 is true, so B is printed.

Q4.
Which loop executes at least once regardless of condition?
Afor
Bwhile
Cdo-while
DNone
Show Answer & Explanation

Correct Answer: C — do-while

do-while checks condition after executing loop body.

Q5.

What will be the output?


int i;
for(i=0;i<3;i++);
printf("%d", i);
A0
B2
C3
DInfinite loop
Show Answer & Explanation

Correct Answer: C — 3

Semicolon makes loop body empty; loop runs fully.

Q6.
Which keyword is used to skip current iteration?
Abreak
Bcontinue
Cgoto
Dpass
Show Answer & Explanation

Correct Answer: B — continue

continue skips remaining statements of current iteration.

Q7.

What will be the output?


int i=1;
while(i<=5)
{
  if(i==3) break;
  printf("%d", i);
  i++;
}
A123
B12
C1234
DInfinite loop
Show Answer & Explanation

Correct Answer: B — 12

Loop breaks when i becomes 3.

Q8.
Which of the following is true about switch?
AWorks with float
BWorks with string
CWorks with int/char
DNeeds break always
Show Answer & Explanation

Correct Answer: C — Works with int/char

switch supports integral constant expressions.

Q9.

What will be the output?


int i=0;
do
{
  printf("%d", i);
  i++;
}while(i<0);
ANo output
B0
C01
DInfinite loop
Show Answer & Explanation

Correct Answer: B — 0

do-while executes once before checking condition.

Q10.
Which loop is best when number of iterations is known?
Awhile
Bdo-while
Cfor
Dgoto
Show Answer & Explanation

Correct Answer: C — for

for loop is preferred when iteration count is known.

Q11.

What will be the output?


int i;
for(i=1;i<=5;i++)
{
  if(i==4) continue;
  printf("%d", i);
}
A12345
B1235
C1245
DInfinite
Show Answer & Explanation

Correct Answer: B — 1235

continue skips printing when i=4.

Q12.
Which of the following is invalid?
Aif()
Bif(a>b)
Cif a>b
Dnested if
Show Answer & Explanation

Correct Answer: C — if a>b

Condition must be inside parentheses.

Q13.

What will be the output?


int i=5;
while(i--)
  printf("%d", i);
A43210
B54321
C4321
DError
Show Answer & Explanation

Correct Answer: A — 43210

Post-decrement evaluates then decrements.

Q14.
Which statement transfers control unconditionally?
Abreak
Bcontinue
Cgoto
Dreturn
Show Answer & Explanation

Correct Answer: C — goto

goto jumps unconditionally to labeled statement.

Q15.

What will be the output?


int x=1;
switch(x)
{
  case 1: printf("A");
  case 2: printf("B");
  default: printf("C");
}
AA
BAB
CABC
DAC
Show Answer & Explanation

Correct Answer: C — ABC

Without break, execution falls through all cases.

Q16.
Which loop checks condition before execution?
Afor
Bwhile
Cdo-while
DBoth for and while
Show Answer & Explanation

Correct Answer: D — Both for and while

Both test condition before entering loop body.

Q17.

What will be the output?


int i=0;
for(;i<3;)
{
  printf("%d", i);
  i++;
}
A012
B123
CInfinite
DError
Show Answer & Explanation

Correct Answer: A — 012

All expressions in for loop are optional.

Q18.
Which of the following is true about break?
ATerminates program
BSkips iteration
CExits loop/switch
DPauses loop
Show Answer & Explanation

Correct Answer: C — Exits loop/switch

break exits nearest loop or switch.

Q19.

What will be the output?


int i=1;
while(i<=3)
{
  printf("%d", i++);
}
A123
B012
C234
DInfinite
Show Answer & Explanation

Correct Answer: A — 123

Post-increment prints then increments.

Q20.
Which of the following cannot be used in condition?
ARelational operator
BLogical operator
CAssignment operator
DAll can be used
Show Answer & Explanation

Correct Answer: D — All can be used

Assignment in condition is allowed but risky.

Q21.

What will be the output?


int i=0;
while(i<3)
  printf("%d", i++);
A012
B123
CInfinite
DError
Show Answer & Explanation

Correct Answer: A — 012

i increments after printing.

Q22.
Which is an infinite loop?
Afor(;;)
Bwhile(1)
Cdo{}while(1)
DAll
Show Answer & Explanation

Correct Answer: D — All

All represent infinite loops.

Q23.

What will be the output?


int x=2;
if(x==2)
  printf("A");
else
  printf("B");
AA
BB
CError
DNo output
Show Answer & Explanation

Correct Answer: A — A

x==2 is true, so A is printed.

Q24.
Which keyword exits function immediately?
Abreak
Bcontinue
Creturn
Dexit
Show Answer & Explanation

Correct Answer: C — return

return transfers control back to caller.

Q25.

What will be the output?


int i;
for(i=0;i<5;i++)
{
  if(i==2) break;
  printf("%d", i);
}
A012
B01
C0123
DError
Show Answer & Explanation

Correct Answer: B — 01

Loop breaks when i equals 2.

Q26.
switch expression must be of type:
Afloat
Bdouble
Cint/char
Dstring
Show Answer & Explanation

Correct Answer: C — int/char

Only integral types allowed.

Q27.

What will be the output?


int i=1;
do
{
  printf("%d", i);
  i++;
}while(i<=3);
A123
B012
CInfinite
DError
Show Answer & Explanation

Correct Answer: A — 123

do-while prints before checking condition.

Q28.
Which loop is entry-controlled?
Ado-while
Bfor
Cwhile
DBoth for and while
Show Answer & Explanation

Correct Answer: D — Both for and while

Condition checked before entering loop.

Q29.

What will be the output?


int x=0;
if(!x)
  printf("True");
ATrue
BFalse
C0
DError
Show Answer & Explanation

Correct Answer: A — True

!0 evaluates to true.

Q30.
Which statement can be used inside switch?
Acontinue
Bbreak
Creturn
DAll
Show Answer & Explanation

Correct Answer: D — All

All are valid inside switch (context dependent).

Q31.

What will be the output?


int i;
for(i=5;i>0;i--)
  printf("%d", i);
A54321
B12345
C43210
DError
Show Answer & Explanation

Correct Answer: A — 54321

Loop decrements and prints.

Q32.
Which of the following is NOT a looping statement?
Afor
Bwhile
Cif
Ddo-while
Show Answer & Explanation

Correct Answer: C — if

if is a decision statement.

Q33.

What will be the output?


int i=0;
while(++i < 4)
  printf("%d", i);
A123
B012
C234
DError
Show Answer & Explanation

Correct Answer: A — 123

Pre-increment increments before comparison.

Q34.
Which statement skips remaining loop and continues next iteration?
Abreak
Bcontinue
Creturn
Dgoto
Show Answer & Explanation

Correct Answer: B — continue

continue skips to next iteration.

Q35.

What will be the output?


int i=1;
for(;;)
{
  if(i>3) break;
  printf("%d", i);
  i++;
}
A123
B012
CInfinite
DError
Show Answer & Explanation

Correct Answer: A — 123

Loop breaks explicitly.

Q36.
Which of the following is true?
Aswitch needs default
Bdefault executes first
Cdefault is optional
Dbreak is mandatory
Show Answer & Explanation

Correct Answer: C — default is optional

default case is optional.

Q37.

What will be the output?


int x=5;
if(x--)
  printf("A");
AA
BNo output
CError
DUndefined
Show Answer & Explanation

Correct Answer: A — A

Post-decrement evaluates before decrement.

Q38.
Which control statement can be nested?
Aif
Bloops
Cswitch
DAll
Show Answer & Explanation

Correct Answer: D — All

All control statements can be nested.

Q39.

What will be the output?


int i=0;
do
{
  i++;
}while(i<3);
printf("%d", i);
A2
B3
C4
DError
Show Answer & Explanation

Correct Answer: B — 3

Loop runs until i reaches 3.

Q40.
Which statement is used to exit from loop and switch both?
Acontinue
Breturn
Cbreak
Dgoto
Show Answer & Explanation

Correct Answer: C — break

break exits nearest loop or switch.