Back to Practice C Programming

Decision Control & Loops - Practice MCQs for CCAT

50 Questions Section B: Programming C Programming

Decision Control & Loops Question Bank for C-CAT

Topic-wise Decision Control & Loops MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.

What will be the output?

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

Correct Answer: A - 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");
AB
BA
CC
DNo output
Show Answer & Explanation

Correct Answer: A - 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
CInfinite loop
D3
Show Answer & Explanation

Correct Answer: D - 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
CNeeds break always
DWorks with int/char
Show Answer & Explanation

Correct Answer: D - 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
Cgoto
Dfor
Show Answer & Explanation

Correct Answer: D - 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);
}
A1235
B12345
C1245
DInfinite
Show Answer & Explanation

Correct Answer: A - 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
BABC
CAB
DAC
Show Answer & Explanation

Correct Answer: B - ABC

Without break, execution falls through all cases.

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

Correct Answer: B - 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++;
}
AInfinite
B123
C012
DError
Show Answer & Explanation

Correct Answer: C - 012

All expressions in for loop are optional.

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

Correct Answer: A - Exits loop/switch

break exits nearest loop or switch.

Q19.

What will be the output?

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

Correct Answer: D - 123

Post-increment prints then increments.

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

Correct Answer: C - 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++);
AError
B123
CInfinite
D012
Show Answer & Explanation

Correct Answer: D - 012

i increments after printing.

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

Correct Answer: C - All

All represent infinite loops.

Q23.

What will be the output?

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

Correct Answer: B - A

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

Q24.
Which keyword exits function immediately?
Abreak
Bcontinue
Cexit
Dreturn
Show Answer & Explanation

Correct Answer: D - 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
BError
C0123
D01
Show Answer & Explanation

Correct Answer: D - 01

Loop breaks when i equals 2.

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

Correct Answer: A - int/char

Only integral types allowed.

Q27.

What will be the output?

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

Correct Answer: D - 123

do-while prints before checking condition.

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

Correct Answer: B - Both for and while

Condition checked before entering loop.

Q29.

What will be the output?

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

Correct Answer: C - True

!0 evaluates to true.

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

Correct Answer: B - 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);
A012
B123
C234
DError
Show Answer & Explanation

Correct Answer: B - 123

Pre-increment increments before comparison.

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

Correct Answer: C - continue

continue skips to next iteration.

Q35.

What will be the output?

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

Correct Answer: B - 123

Loop breaks explicitly.

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

Correct Answer: A - default is optional

default case is optional.

Q37.

What will be the output?

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

Correct Answer: C - A

Post-decrement evaluates before decrement.

Q38.
Which control statement can be nested?
AAll
Bloops
Cswitch
Dif
Show Answer & Explanation

Correct Answer: A - 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
Cgoto
Dbreak
Show Answer & Explanation

Correct Answer: D - break

break exits nearest loop or switch.

Q41.

What is the output of this code?

for(int i = 0; i < 5; i++) {
    if(i == 3) continue;
    printf("%d ", i);
}
A0 1 2 3 4
B0 1 2 4
C0 1 2
D1 2 4
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.

Q42.

What will be printed?

int x = 2;
switch(x) {
    case 1: printf("One ");
    case 2: printf("Two ");
    case 3: printf("Three ");
    default: printf("Default");
}
ATwo Three Default
BTwo Three
CTwo
DOne Two Three 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.

Q43.

How many times will 'Hello' be printed?

int i = 0;
do {
    printf("Hello\n");
    i++;
} while(i < 0);
A0 times
BCompilation error
CInfinite times
D1 time
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.

Q44.

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);
    }
}
A11 21 31
B11 12 13 21 22 23 31 32 33
C11 12 21 22 31 32
D11
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.

Q45.

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);
AFizz
BBuzz
CFizzBuzz
D15
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.

Q46.

What is the output?

int i;
for(i = 0; i < 10; i++) {
    if(i * i > 20) break;
}
printf("%d", i);
A5
B4
C6
D10
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.

Q47.

What happens when the following code is compiled and run?

int x = 0;
while(x);
    printf("Executed");
ANothing is printed
BInfinite loop
C"Executed" is printed once
DCompilation error
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.

Q48.

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);
A10
B16
C6
D8
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.

Q49.

What is the output?

int val = 3;
switch(val) {
    case 1 ... 3:
        printf("Low");
        break;
    case 4 ... 6:
        printf("Mid");
        break;
    default:
        printf("High");
}
ALow
BMid
CHigh
DCompilation error (standard C does not support range in case)
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.

Q50.

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);
A5050
B2550
C2500
D5000
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.

Showing 1-10 of 50 questions