+ 1

How i am getting this output ?

int a = 3; int b = ((++a) * (++a)); cout<< b; output :- 25 . How ????

12th Sep 2016, 7:04 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
9 Answers
+ 2
If ++ is before variable, it at first increments all variables, and then it counts arithmetic operations. It means (++a) * (++a) = (++3) * (++3) = (4) * (++4)= (5) * (5) = 25.
12th Sep 2016, 7:19 AM
Vitali Bassov
Vitali Bassov - avatar
+ 2
But this gives the answer as 80 . int a = 2; int b = ((++a) * (++a) * (++a)); cout<< b; output :- 80. if we apply your logic , then it would look like this , It means (++a) * (++a) *(++a)= (++2) * (++2)*(++2) = (3) * (++3)*(++3). (4)*(4)*(++4) (5)*(5)*(5) =125
12th Sep 2016, 7:26 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
+ 2
but i am getting 80 for a = 2 .
12th Sep 2016, 8:29 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
+ 1
This logic fails here... (++a)*(++a)=(++3)*(++3)= =(4)*(++4)= =(4)*(5)= 20
12th Sep 2016, 7:06 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
+ 1
someone help please
12th Sep 2016, 7:06 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
+ 1
explaination by vitali is correct output of a=2; (++a)*(++a)*(++a); is 125
12th Sep 2016, 8:20 AM
Shaurya Agnihotri
+ 1
Bro... Output depends from compiler to compiler.. some will say 20 some 25.. so its difficult to predict..
12th Sep 2016, 9:49 AM
Soutik
Soutik - avatar
+ 1
ok.. i got it now.. Thanks everyone
12th Sep 2016, 10:41 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
0
For a=2.. (++a)*(++a)*(++a).. I'm getting 60 . so no one say anything
12th Sep 2016, 9:55 AM
Soutik
Soutik - avatar