Control Instructions Questions
Practice Control Instructions MCQs with answers and explanations. Page 2 of 3.
Category
C# Programming
Topic
Control Instructions
Page
2 / 3
Mode
Practice
Questions
Open any question to view the answer and explanation.
C#.NET — Control flow semantics: switch, goto/continue, jump statements, and do loops.
Which statements are correct?
Open
View answer
Evaluate short-circuit and precedence for logical operators in C. What is printed?
#include<stdio.h>
int main()
{
int x, y, z;
x = y = z = 1;
z = ++x || ++y && ++z;
printf("x=%d, y=%d, z=%d
", x, y, z);
return 0;
}
Assume standard operator precedence (&& before ||) and short-circuit evaluation.
Open
View answer
In C programming, what will be the output of the following program?
#include<stdio.h>
int main()
{
char ch;
if (ch = printf(""))
printf("It matters
");
else
printf("It doesn't matters
");
return 0;
}
Open
View answer
In C (16-bit <em>short int</em>), what will this program print? Assume a short int is 2 bytes.
#include<stdio.h>
int main()
{
short int i = 0;
for (i <= 5 && i >= -1; ++i; i > 0)
printf("%u,", i);
return 0;
}
Open
View answer
C (16-bit unsigned int assumed): what does this program print?
#include<stdio.h>
int main()
{
unsigned int i = 65536; /* Assume 2 byte integer */
while (i != 0)
printf("%d", ++i);
printf("
");
return 0;
}
Open
View answer
Evaluate the output of this C program that uses logical negation:
#include<stdio.h>
int main()
{
int x = 10, y = 20;
if (!(!x) && x)
printf("x = %d
", x);
else
printf("y = %d
", y);
return 0;
}
Open
View answer
On a 16-bit <em>unsigned int</em>, determine the behavior of this loop (does it terminate, and what does it print)?
#include<stdio.h>
int main()
{
unsigned int i = 65535; /* Assume 2 byte integer */
while (i++ != 0)
printf("%d", ++i);
printf("
");
return 0;
}
Open
View answer
Floating-point comparison in C: given <code>float a = 0.7;</code>, what will this program print and why?
#include<stdio.h>
int main()
{
float a = 0.7;
if (0.7 > a)
printf("Hi
");
else
printf("Hello
");
return 0;
}
Open
View answer
Spot the effect of a stray semicolon after a <code>for</code> loop in C. What does this program print?
#include<stdio.h>
int main()
{
int i = 0;
for (; i <= 5; i++);
printf("%d", i);
return 0;
}
Open
View answer
Trace the output for the following C program with post-decrement in the condition and multiple loops:
#include<stdio.h>
int main()
{
int i = 5;
while (i-- >= 0)
printf("%d,", i);
i = 5;
printf("
");
while (i-- >= 0)
printf("%i,", i);
while (i-- >= 0)
printf("%d,", i);
return 0;
}
Open
View answer
What is the output of this <code>switch</code> statement in C? Note the statement before any <code>case</code> label.
#include<stdio.h>
int main()
{
int i = 1;
switch (i)
{
printf("Hello
");
case 1:
printf("Hi
");
break;
case 2:
printf("Bye
");
break;
}
return 0;
}
Open
View answer
Evaluate the conditional (ternary) operator: what does this program print?
#include<stdio.h>
int main()
{
int k, num = 30;
k = (num < 10) ? 100 : 200;
printf("%d
", num);
return 0;
}
Open
View answer
In C programming, evaluate the conditional operator used with lvalues (addresses): what is the output?
#include<stdio.h>
int main()
{
int a=0, b=1, c=3;
((a)? &b : &a) = a? b : c;
printf("%d, %d, %d
", a, b, c);
return 0;
}
Open
View answer
In C, how does == behave when comparing an int and a float with equal numeric value?
#include<stdio.h>
int main()
{
int x = 3;
float y = 3.0;
if(x == y)
printf("x and y are equal");
else
printf("x and y are not equal");
return 0;
}
Open
View answer
C switch fall-through with a default label before cases: determine program output
#include<stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("This is default
");
case 1:
printf("This is case 1
");
break;
case 2:
printf("This is case 2
");
break;
case 3:
printf("This is case 3
");
}
return 0;
}
Open
View answer
Operator precedence with logical NOT (!) and relational >= : evaluate the output
#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %d
", b, c);
return 0;
}
Open
View answer
Uninitialized variable inside a conditional path: determine printed values
#include<stdio.h>
int main()
{
int a = 300, b, c;
if(a >= 400)
b = 300;
c = 200;
printf("%d, %d, %d
", a, b, c);
return 0;
}
Open
View answer
Ternary operator used as a format selector in printf: what is printed?
#include<stdio.h>
int main()
{
char str[] = "C-program";
int a = 5;
printf(a > 10 ? "Ps
" : "%s
", str);
return 0;
}
Open
View answer
Loop control with a signed char counter: how many values print?
#include<stdio.h>
int main()
{
char j = 1;
while(j < 5)
{
printf("%d, ", j);
j = j + 1;
}
printf("
");
return 0;
}
Open
View answer
Is continue allowed directly inside a switch statement without an enclosing loop?
#include<stdio.h>
int main()
{
int i=3;
switch(i)
{
case 1:
printf("Hello
");
case 2:
printf("Hi
");
case 3:
continue;
default:
printf("Bye
");
}
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.