What is the output of the following program ? main (){ int x = 2, y = 5; if(x…
2018
What is the output of the following program ?
main (){
int x = 2, y = 5;
if(x < y) return (x = x + y);
else printf ("z1");
printf("z2");
- A.
z2
- B.
z1z2
- C.
Compilation error
- D.
None of these
Attempted by 685 students.
Show answer & explanation
Correct answer: D
The condition (x < y) evaluates to true since 2 is less than 5. The code executes the return statement, which terminates the function immediately. Therefore, the printf statements are unreachable and no output is produced.