+ 2
What's the output?
10 Antworten
+ 2
Hmm. Think this like this:
int y = ++x * ++x is equal to:
x = x + 1 //6
x = x + 1 //7
int y = x * x //49
So the multiplication happens after increments happen. This is because prefix increments (++x) happens before the statement executes.
+ 3
x becomes 6 at the first part and then 7 at the second part. After that the multiplication happens so it is 7*7. I think this is why.
+ 3
Ah, also, the output will be 742 in Java, C# languages like your prediction. C++ has some undefined behaviour. For more information again check this site:
https://stackoverflow.com/questions/6457130/pre-post-increment-operator-behavior-in-c-c-java-c-sharp
+ 2
but it should be.. 742 according to logic. which says
++x(value 6)*++x(value7)
that's 42
+ 2
exactly.. but why we get 7*7=49 as output
+ 2
but the 1st value of ++x should be taken as 6 & next ++x should be taken as 7, what's the reason of both being taken as 7, but it's not in the other cases of x++ or --x.
+ 2
This time x++ is postfix and it effects the right x value but doesn't increment itself before the statement executes. You can check this link to get deep information about these:
https://stackoverflow.com/questions/7031326/what-is-the-difference-between-prefix-and-postfix-operators
+ 2
okay okay got u.. thanks!
+ 1
x=5;
y=x++*x;
cout<<x<<y;
gives 630 ie 6, 5*6 as o/p .
why not it takes the 6 as both the values?