+ 2

What is the value of a...

int a = 7, i,c; if (a<8) for(i=0;i<a;i++) i += i; a = i + ++i;

31st Dec 2016, 10:04 AM
Sohel Siddique
Sohel Siddique - avatar
9 Answers
+ 3
Again? 16
31st Dec 2016, 10:23 AM
Dao
Dao - avatar
+ 3
@Ken Ah, my bad. You're right. He's tagged all languages. Thought it was a C++ specific
31st Dec 2016, 1:06 PM
Vishal++
Vishal++ - avatar
+ 2
Testing would clarify, but in the last line, I think the increment happens before the addition, making it 8 + 8
31st Dec 2016, 10:36 AM
Dao
Dao - avatar
+ 1
Could someone explain why c++ gives 16?
31st Dec 2016, 11:09 AM
MarcinPL
MarcinPL - avatar
+ 1
Aaaah clever quizz. Yes Ken is right, the unary increment takes priority over the sum, making it 16. With this compiler at least (this is why it could be different with other languages).
31st Dec 2016, 11:23 AM
ifl
ifl - avatar
+ 1
Don't you dare, this question isn't suitable. The results differ depending on the programming language. The syntax doesn't seem to belong to any specific language, and he declared a variable that he never used (c).
31st Dec 2016, 1:02 PM
Dao
Dao - avatar
+ 1
I think everybody here's pretty chill, I was the only one to get a little excited, just because some questions added to the quiz factory aren't suitable, so I wanted to prevent anyone from trying to add this one.
31st Dec 2016, 9:39 PM
Dao
Dao - avatar
0
hhhhh....guys just chill...... i am new in programming, still i m learning... so sorry for the inconvenience....
31st Dec 2016, 9:27 PM
Sohel Siddique
Sohel Siddique - avatar