+ 11
Why the answer is 19?
#include <iostream> using namespace std; int main() { int x=4; int y=++x + ++x + ++x; cout<<y; return 0; // answer is 19 } Can someone explain why is 19? I got 18. Here is how I did: x=x+1. 4+1=5 x=x+1. 5+1=6 x=x+1. 6+1=7 y=x+x+x. y=5+6+7=18 What am I doing wrong?
6 Respuestas
+ 2
Jacob Burgess I am guessing kms does not stand for kilometres?
+ 1
++x = 1+4 = 5
1+4 = 5
+ ++x = 1+1+5 = 7
5+2 = 7
+ ++x = 1+1+5 = 7
7+2 = 7
ans. 5+7+7 = 19
final ans. 19
0
Answer = 5 + 5 + 9 = 19
0
Hw these area available guys
0
It's purely compiler dependent
- 1
x= x+1 => 4+1=5
x= x => 5
y= x +1 + x => 10
y=(x +1+ (x +1))+ 1 => y = 11
x =((( x + 1)+1)+1 ) + 1=> x = 8
y = 8 + 11 = 19