Guys please tell me how does it comes | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

Guys please tell me how does it comes

https://code.sololearn.com/crFIz1O78ogS/?ref=app According to me value of ans should be 11 not 12

8th Sep 2017, 1:58 PM
$h@dow
$h@dow - avatar
9 Réponses
+ 6
it did not work that way in c++ the compiler incremented i twice before adding the values it was this way I = 4 I = 5 I = 6 6 + 6 = 12
8th Sep 2017, 5:26 PM
Lord Krishna
Lord Krishna - avatar
+ 6
here's a similar question the value of i was incremented twice just like here https://www.sololearn.com/Discuss/694235/?ref=app
8th Sep 2017, 5:29 PM
Lord Krishna
Lord Krishna - avatar
+ 5
i have explained the Javascript behaviour a little check that you will understand a little in the code. //not great at explanation ask about the JS example I will tell. about c++ it's related to compiler .
8th Sep 2017, 5:20 PM
Lord Krishna
Lord Krishna - avatar
+ 4
it's some compiler quirk from c++. the same logic on JavaScript gives a little different answer https://code.sololearn.com/cL2G2m34vtCQ/?ref=app https://code.sololearn.com/WDL323eYSVtv/?ref=app
8th Sep 2017, 5:02 PM
Lord Krishna
Lord Krishna - avatar
+ 1
Answer is 11 18 26 on javascript
8th Sep 2017, 5:08 PM
$h@dow
$h@dow - avatar
+ 1
Eg: i=4; Ans=++i + ++i + ++i ++i=5 ++i=6 ++i=7 Ans=7+7+7 =21 but answer should be 18
8th Sep 2017, 5:32 PM
$h@dow
$h@dow - avatar
0
I understood how does it works in javascript But in c++ i=4 Then ++i=5 So ans=++i + ++i =5+6 =11 not 12
8th Sep 2017, 5:24 PM
$h@dow
$h@dow - avatar
0
So according to the value ans2 will be 21
8th Sep 2017, 5:29 PM
$h@dow
$h@dow - avatar
0
@lord krishna your theory will only work for 2 oprands not for 3
8th Sep 2017, 5:30 PM
$h@dow
$h@dow - avatar