+ 2
How output getting for this
int a=2; int b=3; a+= ++a * b; cout <<a;
8 Respostas
+ 2
12
1. ++a=3
2. ++a*b=9
3. a+=++a*b=12
C++ starts to process from immediately right side of an equivalance
+ 3
Alwayzz remember that SL provides code playground
You can test your programs there toođ
if u dnt knw a answr take a screenshot and test it in code playgroundđâïžđ
+ 2
1. x+=x means x=x+x
2. So a+=++a*b means a=++a*b+a
+ 2
int a,b;
a=2; // ++a=3 value of a now used is 3
b=3;
a+=++a*b; /*you can interpret it as........
x+=(something);
is equivalent to
x=x+(something);
Same applicable here as
a+= ++a * b;
is equivalent to
a= ++a + (++a*b);
so you'll be getting a= 3+(3*3)=12*/
+ 1
lil confused with third line.. result of ++a*b=9.. ok..but how dat 9 becomes 12 when operates with "a+=" in the 3rd line..
how dat a+= (I think itz equivalent to ++a) works here
+ 1
No actually not if a variable's value incremented by preincrement operator it effects the value throughout scope hence a's initial value becomes 3 and remains so unless changed.
0
Thank you!
0
:)