in Programming in C edited by
9,845 views
5 votes
5 votes

What is the output of tho following program?

main(){
    int x=2, y=5;
    if(x<y) return (x=x+y);
            else printf("z1");
    printf("z2");
}
  1. $z2$
  2. $z1z2$
  3. Compilation error
  4. None of these
in Programming in C edited by
by
9.8k views

4 Comments

option D is correct.
0
0
yes the answer is correct. option D.
2
2
why “ printf("z2");” is not executed?
1
1
Returning int without specifying return type is a compiler error since c99.

https://stackoverflow.com/questions/30542092/function-without-return-type-specified-in-c
0
0

6 Answers

8 votes
8 votes
Best answer
This code will first replace value of variable x by (5+2)=7 because x<y.Then x will return it's current value 7.So no output will be printed.i.e option D is correct.
selected by

3 Comments

https://ideone.com/9XlV6U

It throws runtime error

0
0
1
1
Use standard c compiler
0
0
1 vote
1 vote
answer is (D)
edited by
1 vote
1 vote
option D is correct
1 vote
1 vote

None of these. (D)
Runtime Error

2 Comments

can anyone explain why it is not showing any output?
0
0

because of return statement. it terminates the code. in the code was like

#include<stdio.h>

int main (){

int x=2, y=5;

if (x<y) return printf(“%d”,x+y);

else printf(“z1”);

printf(“z2”);

}

in the above case the output will be 7 because once the “return” function is executed, the whole code will be terminated. 

0
0
Answer:

Related questions