a=4
b= ++a + ++a + ++a;
In C++ b is 21
In C# b is 18.
Why such a radical difference in operators implementation?
Pre/post incrementing operators
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhay ShankerRank #375 · 6.7K reputationPosted Nov 29, 2013, 1:11 AM EST
In C++, the order of evaluation of subexpressions is unspecified whereas C# evaluate expressions from left to right, and the side-effects are visible immediately
VulpesRank #55 · 29.2K reputationPosted Nov 29, 2013, 3:53 AM EST