+ 3
Hey friends please explain me this code and say why its output is 1120?
#include <iostream> using namespace std; int main() { int x=1,y=2; for(x<=4;y--;x++) cout<<x<<y; return 0; } //output is 1120
4 Antworten
+ 3
The loop ends when y = 0 (because 0 is considered false)
1. y is decremented, prints x which is 1 followed by y which is also 1, increments x to 2
2. decrements y (the loop does not stop imediatly because first the value of y is used then it is decremented)
prints x which is 2 followed by y which is 0, increments x;
3. loop ends;
+ 2
bcz everything y is decrement ed to 1 and x is increment to 1
0
we are checking condition only for x, so value of y won't affect the loop.
but how it will yields 1120 output???
0
can any 1 please explain the above code, still I m not getting