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");

Answer: D. None of theseThe condition (x < y) evaluates to true since 2 is less than 5. The code executes the return statement, which terminates the function immediately. Therefore,…

  1. A.

    z2

  2. B.

    z1z2

  3. C.

    Compilation error

  4. D.

    None of these

Attempted by 1029 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.

Explore the full course: Coal India Management Trainee

Loading lesson…