in c language say x=10 then in next line y= --x + --x + --x then the output is 23 instead of 24 can anyone explain | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

in c language say x=10 then in next line y= --x + --x + --x then the output is 23 instead of 24 can anyone explain

#include"studio.h" int(main) { int x=10; int y= --x + --x + --x; printf("%d",y); return 0; } Output : 23

8th Jun 2022, 1:52 PM
Pushkar Roy
Pushkar Roy - avatar
3 Answers
0
I would like to note here that you have syntax error in that snippet. 1. There's no "studio.h", it is <stdio.h> 2. Use double quotes for inclusion of custom and 3rd party headers only. Use angle brackets for inclusion of built-in headers e.g. <stdio.h> 3. The main function signature was incorrectly written, please refer here https://en.cppreference.com/w/c/language/main_function
8th Jun 2022, 2:30 PM
Ipang
0
Buddy leave the syntax explain the result you can do it
8th Jun 2022, 5:36 PM
Pushkar Roy
Pushkar Roy - avatar
0
Many people had come up with doubts around this issue. If I may, I would first recommend you to never mix data modification and data access in one execution sequence, the result is unpredictable. Some may argue, that operator precedence and/or associativity plays a role. It's fine, except the fact that the standards does not dictate the order of execution where data modification and data access are performed in one execution sequence. Compiler vendors are free to implement how such situations are handled. So what does it mean? it means, what we get from one compiler *may* differ to that of others. I could simply say the expression was evaluated as 9 + 8 + 7 which yields 24. But as you have witnessed, there exists a chance for a different result. Syntax error ignored won't do any help.
9th Jun 2022, 6:21 AM
Ipang