Vidyalelo
C Programming · Q126

Control Structures

Programming · C Programming · question 126

Q126

What will be the output of the following C code? #include int main() switch (printf("Do")) case 1: printf("First "); break; case 2: printf("Second "); break; default: printf("Default "); break;

A.
Do
B.
DoFirst
C.
DoSecond
Answer
D.
DoDefault

Answer: Option C

Solution

Answer: Option C
Solution:
In this code, the switch statement is evaluating the result of the printf("Do") function call. The printf() function returns the number of characters printed.

When printf("Do") is executed, it prints "Do" to the standard output and returns the number of characters printed, which is 2.

So, the switch statement evaluates the value 2.

Since there is a case 2 in the switch statement, it will execute the corresponding code block, which prints "Second" to the standard output.

Therefore, the correct output of the code will be DoSecond. So, the correct answer is Option C: DoSecond.