0

Int main() int a=5 Int b=++a*a++ Print(%d,b)

please explain how output is 42.ignore syntax errors.

6th Jun 2017, 3:34 PM
Nitish Kulkarni
Nitish Kulkarni - avatar
8 Respostas
+ 1
(++a = 6) * (a++ = 7) = 42
6th Jun 2017, 4:01 PM
Scott Nunemacher
Scott Nunemacher - avatar
+ 1
@scott i understand how ++a is 6 but a++ should be 6 as well because a++ evaluates first then it increments.so i think answer should be 36=6*6
6th Jun 2017, 4:25 PM
Nitish Kulkarni
Nitish Kulkarni - avatar
0
i agree how ++a is 6 but a++ evaluate first then its increments so i think a++ is 6.so answwr will be 36.can u explain how a++ is 7.?
6th Jun 2017, 4:26 PM
Nitish Kulkarni
Nitish Kulkarni - avatar
0
@Nitish, i had an answer for you before i saw you had a c++ tag for this. I don't know if you know this is a JavaScript q&a.
7th Jun 2017, 2:49 AM
Scott Nunemacher
Scott Nunemacher - avatar
0
My new answer is if this was c++ your answer 36 would probably be correct. If JavaScript, then it's syntactically written incorrectly so it would (and did) console.log() to 36.
7th Jun 2017, 2:52 AM
Scott Nunemacher
Scott Nunemacher - avatar
0
but in c++ i got answer 42 not 36
7th Jun 2017, 6:20 AM
Nitish Kulkarni
Nitish Kulkarni - avatar
0
++a=6..it will Increment the value of a=5...then a++=7..because this will increment the value of a..which was incremented before(a=6)
10th Jun 2017, 10:12 AM
Abdullah
Abdullah - avatar
0
a++ will be 6 because it will execute first then incremental like if i=5 j=i++ then i=6 and j=5
10th Jun 2017, 12:59 PM
Nitish Kulkarni
Nitish Kulkarni - avatar