Can any one explian me why the output is all 1 for this code? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 4

Can any one explian me why the output is all 1 for this code?

https://code.sololearn.com/cu7gKp7uNqOX/?ref=app

15th Jun 2018, 2:09 PM
thealoneprogrammer
thealoneprogrammer - avatar
4 Réponses
+ 5
yes i agree with your answers Sanjay K Hegde and D⚽⚽⚽⚽7⃣7⃣7⃣ but what do u think the evaluation takes place from left to right or right to left? (that matters i guess)
16th Jun 2018, 3:14 AM
thealoneprogrammer
thealoneprogrammer - avatar
+ 5
Rithesh R give challenge to Subramanya 😂
18th Jun 2018, 8:33 AM
thealoneprogrammer
thealoneprogrammer - avatar
+ 2
You are using pre increment=> ++I, and post increment => I++. When using pre increment first you are changing the value and after that assign it to the variable. It's exactly the opposite in post increment first assign the value and after that change it. That's why your output is containing "1". You can see the explanation here www.quora.com/What-is-the-difference-between-pre-increment-and-post-increment-operator-in-C++-What-is-the-difference-between-code-a++-code-and-code-++a-code-in-C++
15th Jun 2018, 5:50 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
Instead of assigning the value of x....just use x++; Then that prints one incremented value int x=1; x++; printf("%d",x); o/p: 2 same as decrement.... In your case you assigned the value to x ,So x is just increments and then returned to its original value.....thats y ur ans is 1
15th Jun 2018, 6:29 PM
Sanjaykrishna Hegade 🇮🇳
Sanjaykrishna Hegade 🇮🇳 - avatar