Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
What is the behavior of goto in C?
Correct Answer:
A. It transfers control to a labeled statement
EXPLANATION
goto transfers program control to a labeled location, though it's discouraged for code readability.
Analyze the ternary operator: int x = (5 > 3) ? 10 : 20; What is the value of x?
Correct Answer:
A. 10
EXPLANATION
Since 5 > 3 is true, the ternary operator returns 10, so x = 10.
What is the difference between 'break' and 'continue' in loops?
Correct Answer:
A. break exits the loop, continue skips to next iteration
EXPLANATION
break terminates the loop entirely, while continue jumps to the next iteration without executing remaining statements.
What is the output of this code?
for (int i = 0; i < 3; i++)
printf("%d ", i);
for (int i = 0; i < 3; i++)
printf("%d ", i);
Correct Answer:
A. 0 1 2
EXPLANATION
The loop runs from i=0 to i=2 (i < 3), printing '0 1 2 '.
Which of the following is NOT a valid control flow statement in C?
Correct Answer:
B. foreach
EXPLANATION
foreach is not a standard C control flow statement. C has if-else, switch, for, while, do-while, and goto.
What will be the output of the following C code?
int x = 5;
if (x > 3)
printf("A");
else
printf("B");
int x = 5;
if (x > 3)
printf("A");
else
printf("B");
Correct Answer:
A. A
EXPLANATION
Since x = 5 and 5 > 3 is true, the if block executes and prints 'A'.