C Programming - MCQ Practice Questions
Practice free C Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
978 questions | 100% Free
What is the output of the following code? for(int i = 1; i <= 3; i++) { for(int j = 1; j <= 2; j++) { if(i == 2 && j == 1) break; printf("%d%d ", i, j); } }
In a nested loop, if we use 'goto' statement, where does the control transfer?
What is the output? int x = 5; switch(x) { case 5: printf("Five"); case 6: printf("Six"); default: printf("Default"); }
What will be printed? for(int i = 0; i < 3; i++) { if(i == 1) goto skip; printf("%d ", i); } skip: printf("End");
What is the final value of x? int x = 0; for(int i = 1; i <= 5; i++) { if(i % 2 == 0) continue; x += i; }
In a switch statement with integer cases, can a case have a floating-point constant?
What happens with this nested if? if(1) if(0) printf("A"); else printf("B");
Predict the output: for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) if(i + j == 1) continue; printf("Done");
What is the behavior of this code? int i = 0; while(1) { i++; if(i > 5) break; }
Consider the code: int x = 5; if(x > 3) if(x > 10) printf("A"); else printf("B"); Which statement best describes the output?
What does the following code segment accomplish? int i = 0; while(i < 5) { if(i == 2) { i++; continue; } printf("%d ", i); i++; }
Which of the following is a valid use of the switch statement in C?
Analyze: What is printed by this code? for(int i = 1; i <= 3; i++) { for(int j = 1; j <= i; j++) { printf("%d", i); } printf(" "); }
What happens when you use break in a nested loop structure?
Consider the code: int x = 0; while(1) { if(++x > 3) break; printf("%d ", x); } What is the output?
What is the key distinction between if-else and switch statements in terms of evaluation?
What does the following code segment do? int i = 0; do { printf("%d ", i); } while(++i < 3);
Consider: switch(x) { case 1: case 2: case 3: printf("A"); break; default: printf("B"); } What advantage does stacking cases provide?
What does continue do in a for loop with multiple statements in body?
What is the output of the following code? int x = 5; if(x > 3) if(x < 10) printf("Pass"); else printf("Fail");