Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Control Instructions Questions
C#.NET — Control flow semantics: switch, goto/continue, jump statements, and do loops. Which statements are correct?
Evaluate short-circuit and precedence for logical operators in C. What is printed? #include
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.
In C programming, what will be the output of the following program? #include
int main() { char ch; if (ch = printf("")) printf("It matters "); else printf("It doesn't matters "); return 0; }
In C (16-bit
short int
), what will this program print? Assume a short int is 2 bytes. #include
int main() { short int i = 0; for (i <= 5 && i >= -1; ++i; i > 0) printf("%u,", i); return 0; }
C (16-bit unsigned int assumed): what does this program print? #include
int main() { unsigned int i = 65536; /* Assume 2 byte integer */ while (i != 0) printf("%d", ++i); printf(" "); return 0; }
Evaluate the output of this C program that uses logical negation: #include
int main() { int x = 10, y = 20; if (!(!x) && x) printf("x = %d ", x); else printf("y = %d ", y); return 0; }
On a 16-bit
unsigned int
, determine the behavior of this loop (does it terminate, and what does it print)? #include
int main() { unsigned int i = 65535; /* Assume 2 byte integer */ while (i++ != 0) printf("%d", ++i); printf(" "); return 0; }
Floating-point comparison in C: given
float a = 0.7;
, what will this program print and why? #include
int main() { float a = 0.7; if (0.7 > a) printf("Hi "); else printf("Hello "); return 0; }
Spot the effect of a stray semicolon after a
for
loop in C. What does this program print? #include
int main() { int i = 0; for (; i <= 5; i++); printf("%d", i); return 0; }
Trace the output for the following C program with post-decrement in the condition and multiple loops: #include
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; }
What is the output of this
switch
statement in C? Note the statement before any
case
label. #include
int main() { int i = 1; switch (i) { printf("Hello "); case 1: printf("Hi "); break; case 2: printf("Bye "); break; } return 0; }
Evaluate the conditional (ternary) operator: what does this program print? #include
int main() { int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d ", num); return 0; }
In C programming, evaluate the conditional operator used with lvalues (addresses): what is the output? #include
int main() { int a=0, b=1, c=3; ((a)? &b : &a) = a? b : c; printf("%d, %d, %d ", a, b, c); return 0; }
In C, how does == behave when comparing an int and a float with equal numeric value? #include
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; }
C switch fall-through with a default label before cases: determine program output #include
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; }
Operator precedence with logical NOT (!) and relational >= : evaluate the output #include
int main() { int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d ", b, c); return 0; }
Uninitialized variable inside a conditional path: determine printed values #include
int main() { int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d ", a, b, c); return 0; }
Ternary operator used as a format selector in printf: what is printed? #include
int main() { char str[] = "C-program"; int a = 5; printf(a > 10 ? "Ps " : "%s ", str); return 0; }
Loop control with a signed char counter: how many values print? #include
int main() { char j = 1; while(j < 5) { printf("%d, ", j); j = j + 1; } printf(" "); return 0; }
Is continue allowed directly inside a switch statement without an enclosing loop? #include
int main() { int i=3; switch(i) { case 1: printf("Hello "); case 2: printf("Hi "); case 3: continue; default: printf("Bye "); } return 0; }
1
2
3