Control Instructions Questions
Practice Control Instructions MCQs with answers and explanations. Page 3 of 3.
Category
C# Programming
Topic
Control Instructions
Page
3 / 3
Mode
Practice
Questions
Open any question to view the answer and explanation.
Analyze a for-loop with a post-printf expression and boolean control variable: what prints?
#include<stdio.h>
int main()
{
int x=1, y=1;
for(; y; printf("%d %d
", x, y))
{
y = x++ <= 5;
}
printf("
");
return 0;
}
Open
View answer
Empty for-loop control fields in C: is for(;;) valid and what does this program do?
#include<stdio.h>
int main()
{
int i=1;
for(;;)
{
printf("%d
", i++);
if(i>10)
break;
}
return 0;
}
Open
View answer
C language – switch-case validation and constants:
Point out the specific compile-time error(s) in this program.
#include <stdio.h>
int main()
{
int P = 10;
switch (P)
{
case 10:
printf("Case 1");
case 20:
printf("Case 2");
break;
case P:
printf("Case 2");
break;
}
return 0;
}
Open
View answer
C language – while loop syntax sanity check:
Point out the compile-time error (if any) in this loop with a missing condition.
#include <stdio.h>
int main()
{
int i = 1;
while()
{
printf("%d
", i++);
if (i > 10)
break;
}
return 0;
}
Open
View answer
C language – switch body semantics and fall-through behavior:
Identify whether this program has a compilation error and what it prints.
#include <stdio.h>
int main()
{
int i = 1;
switch (i)
{
printf("This is c program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
Open
View answer
C control flow and goto scope rules:
Point out the error in this program that jumps to a label inside another function.
#include <stdio.h>
int main()
{
void fun();
int i = 1;
while (i <= 5)
{
printf("%d
", i);
if (i > 2)
goto here;
i++;
}
return 0;
}
void fun()
{
here:
printf("It works");
}
Open
View answer
C switch-case constants and duplicates:
Which compilation error(s) will be reported for this switch that includes a computed case and a literal with the same value?
#include <stdio.h>
int main()
{
int a = 5;
switch (a)
{
case 1:
printf("First");
case 2:
printf("Second");
case 3 + 2:
printf("Third");
case 5:
printf("Final");
break;
}
return 0;
}
Open
View answer
C conditional operator (?:) usage with assignments:
Determine the program output and understand why the ternary expression is valid.
#include <stdio.h>
int main()
{
int a = 10, b;
a >= 5 ? b = 100 : b = 200;
printf("%d
", b);
return 0;
}
Open
View answer
C switch with computed case labels:
Identify whether this program is valid and if any error exists when case uses an arithmetic expression.
#include <stdio.h>
int main()
{
int i = 1;
switch (i)
{
case 1:
printf("Case1");
break;
case 12+4:
printf("Case2");
break;
}
return 0;
}
Open
View answer
C switch with empty body:
Does the following program contain any error when a switch has no case/default blocks?
#include <stdio.h>
int main()
{
int a = 10;
switch (a)
{
}
printf("This is c program.");
return 0;
}
Open
View answer
C if–else chain and statement termination:
Identify the compilation error in this program with a missing semicolon.
#include <stdio.h>
int main()
{
int x = 30, y = 40;
if (x == y)
printf("x is equal to y
");
else if (x > y)
printf("x is greater than y
");
else if (x < y)
printf("x is less than y
")
return 0;
}
Open
View answer
C conditional operator with assignments – behavior and output:
Is there any error in this program, and what will it print?
#include <stdio.h>
int main()
{
int n = 0, y = 1;
y == 1 ? n = 0 : n = 1;
if (n)
printf("Yes
");
else
printf("No
");
return 0;
}
Open
View answer
In C programming, consider the following code (normalize line breaks exactly as shown):
#include<stdio.h>
int main()
{
int i = 10, j = 15;
if(i % 2 = j % 3)
printf("CuriousTab
");
return 0;
}
Which compiler diagnosis best applies to this program and why?
Open
View answer
In C, analyze the following program and determine the correct behavior (note the real line breaks):
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i = 0;
i++;
if(i <= 5)
{
printf("CuriousTab
");
exit(0);
main();
}
return 0;
}
Which statement best describes what actually happens when it runs?
Open
View answer
Consider this C program (preserve the exact newlines):
#include<stdio.h>
int main()
{
int x = 10, y = 100%90, i;
for(i = 1; i < 10; i++)
if(x != y);
printf("x = %d y = %d
", x, y);
return 0;
}
Which statements about its output and syntax are correct?
Open
View answer
Analyze the following C program (with real newlines) and select the best diagnosis:
#include<stdio.h>
int main()
{
int i = 10, j = 20;
if(i = 5) && if(j = 10)
printf("Have a nice day");
return 0;
}
What is the correct compiler outcome?
Open
View answer
C language theory: Which of the following statements about for, while, and do-while is/are correct?
1) A for loop always runs faster than a while loop.
2) Anything achievable with a for loop can also be written using a while loop.
3) The construct for(;;); creates an infinite loop.
4) A for loop guarantees at least one execution of the loop body.
Open
View answer
C if-else semantics: Which of the following are correct?
1) Every if-else statement can be replaced by an equivalent expression using the ?: (conditional) operator.
2) Nested if-else statements are allowed.
3) Multiple statements are permitted inside an if block.
4) Multiple statements are permitted inside an else block.
Open
View answer
C switch semantics: which statements are correct?
1) switch is useful for testing a variable against a set of specific discrete values.
2) switch is ideal for checking whether a value falls into arbitrary numeric ranges.
3) Compilers often implement a jump table for switch cases (where appropriate).
4) A break is not mandatory after every case label.
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.