C Control Statement Test

This section checks understanding of control statements. It contains 15 solved test programs/questions covering decisions, loops and jump statements.

Syntax / Basic Pattern

Read the question → predict the output → run the program → compare your answer.

 

Easy points to remember

  • Try to predict the output before reading the solution.
  • Pay special attention to loop boundaries and break/continue.
  • For switch, check whether break is present.
📝 TEST METHOD: Try to predict the output before looking at the answer. The 15 solved test programs below are designed as revision questions.

 

Program 1: Test 1: if output

#include <stdio.h>
int main(){int x=10;if(x>5)printf(“YES”);else printf(“NO”);return 0;}

 

OUTPUT
Answer: YES

 

Program 2: Test 2: switch output

#include <stdio.h>
int main(){int x=2;switch(x){case 1:printf(“A”);break;case 2:printf(“B”);break;default:printf(“C”);}return 0;}

 

OUTPUT
Answer: B

 

Program 3: Test 3: for count

#include <stdio.h>
int main(){for(int i=1;i<=3;i++)printf(“%d “,i);return 0;}

 

OUTPUT
Answer: 1 2 3

 

Program 4: Test 4: while count

#include <stdio.h>
int main(){int i=3;while(i>0){printf(“%d “,i);i–;}return 0;}

 

OUTPUT
Answer: 3 2 1

 

Program 5: Test 5: do-while

#include <stdio.h>
int main(){int i=10;do{printf(“X”);i++;}while(i<5);return 0;}

 

OUTPUT
Answer: X

 

Program 6: Test 6: break

#include <stdio.h>
int main(){for(int i=1;i<=5;i++){if(i==3)break;printf(“%d “,i);}return 0;}

 

OUTPUT
Answer: 1 2

 

Program 7: Test 7: continue

#include <stdio.h>
int main(){for(int i=1;i<=5;i++){if(i==3)continue;printf(“%d “,i);}return 0;}

 

OUTPUT
Answer: 1 2 4 5

 

Program 8: Test 8: nested loop

#include <stdio.h>
int main(){for(int i=1;i<=2;i++)for(int j=1;j<=2;j++)printf(“%d%d “,i,j);return 0;}

 

OUTPUT
Answer: 11 12 21 22

 

Program 9: Test 9: casting

#include <stdio.h>
int main(){int a=5,b=2;printf(“%.1f”,(float)a/b);return 0;}

 

OUTPUT
Answer: 2.5

 

Program 10: Test 10: goto

#include <stdio.h>
int main(){goto x;printf(“A”);x:printf(“B”);return 0;}

 

OUTPUT
Answer: B

 

Program 11: Test 11: loop sum

#include <stdio.h>
int main(){int s=0;for(int i=1;i<=4;i++)s+=i;printf(“%d”,s);return 0;}

 

OUTPUT
Answer: 10

 

Program 12: Test 12: switch fall-through

#include <stdio.h>
int main(){int x=1;switch(x){case 1:printf(“A”);case 2:printf(“B”);break;}return 0;}

 

OUTPUT
Answer: AB

 

Program 13: Test 13: nested break

#include <stdio.h>
int main(){for(int i=1;i<=2;i++){for(int j=1;j<=3;j++){if(j==2)break;printf(“%d%d “,i,j);}}return 0;}

 

OUTPUT
Answer: 11 21

 

Program 14: Test 14: if-else range

#include <stdio.h>
int main(){int m=39;if(m>=40)printf(“Pass”);else printf(“Fail”);return 0;}

 

OUTPUT
Answer: Fail

 

Program 15: Test 15: infinite loop with break

#include <stdio.h>
int main(){int i=0;while(1){i++;if(i==3)break;}printf(“%d”,i);return 0;}

 

OUTPUT
Answer: 3
Scroll to Top