+ 1

Why answer is 19?

#include <iostream> using namespace std; int main() { int x, i=4; x=++i + ++i + ++i; cout <<x; return 0; }

8th Nov 2017, 9:24 AM
Dipu S James
5 Answers
+ 9
see here for more information regarding this undefined behaviour. http://en.cppreference.com/w/cpp/language/eval_order
8th Nov 2017, 9:50 AM
jay
jay - avatar
+ 4
I think it does 6 + 6 + 7 (may be in another order) Know that doing more than one increment/decrement like this is undefined in C/C++ standards so it is compiler dependant. What works with gcc might work differently with clang (same for g++ and clang++)
8th Nov 2017, 9:35 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
yep# true depends on compiler###
8th Nov 2017, 9:41 AM
sayan chandra
sayan chandra - avatar
+ 1
in c it's showing answer is 21 Increment the variable I up to break point. Step 2: Start assigning final value 7 to all variable i in the expression. So, i=7+7+7=21
8th Nov 2017, 9:46 AM
Dipu S James
0
yeah... 3 ++i means 4--5--6--7 now 7+7+7 but here it seems... 5+6+7+1 if two ++i 5+6+1
8th Nov 2017, 9:49 AM
sayan chandra
sayan chandra - avatar