+ 6

What is the value of k after operation? int k = 5; k += k++ + ++k; why its output depends on compiler?

24th Dec 2016, 7:29 PM
Ajay Agrawal
Ajay Agrawal - avatar
11 Answers
+ 9
firstly, k=5 ++k , k=6 k++ + ++k, 6+6=12 k+=k++ + ++k, now k++ was activated it made k=7 So finally k = 7+12 = 19
24th Dec 2016, 7:52 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 6
why sololearn rejected that by saying it produces different outputs on different compilers?
24th Dec 2016, 8:00 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 5
Yes, you are right. It can be executed correctly.
15th Jan 2017, 5:45 PM
Rosa
Rosa - avatar
+ 4
bro its high level question in C or other lang.
24th Dec 2016, 7:44 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 4
Sorry, but answer is 19
24th Dec 2016, 7:49 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 4
"why sololearn rejected that by saying it produces different outputs on different compilers?" Because in this expression you have only addition, so you can't determine priority used by each compiler?
24th Dec 2016, 8:11 PM
visph
visph - avatar
+ 4
Sorry bro, you can check on any compiler this code it will give you answer 19
25th Dec 2016, 3:09 AM
Ajay Agrawal
Ajay Agrawal - avatar
+ 2
You, twisted mind Oo
24th Dec 2016, 7:41 PM
visph
visph - avatar
+ 2
I don't think you encounter this each days, and it's easy to clarify the code to avoid problems, at least with parenthesis, if it isn't by divide your one-line instruction to multi-line ones :P
24th Dec 2016, 7:50 PM
visph
visph - avatar
+ 2
K = 16, don't ask how? 🎄😊😀
25th Dec 2016, 1:00 AM
Wilson Bol
Wilson Bol - avatar
0
Answer in bluej is 17 k=5+5+7=17
17th Nov 2022, 8:19 AM
Priyanka sinha
Priyanka sinha - avatar