Simple C Code

Neither, they have added lots of their own features. GCC is in accordance with the standard. I checked the answer on various compilers and got 16 as answer, but in turbo c, the answer was 15. Sorry for my wrong answer.

Yes, It is 15 in turbo c

Thanks @sunny210 :slight_smile: I am happy that I could help you :slight_smile:

@dragonemperor even in C# it is 15 but I am still not getting how could ++x + ++x is equal to 10? which compiler you are using?

What will be the answer for this one :

int x=5;

printf("%d", ++x + x++ + ++x + ++x);

gcc compiler

29
6 (Converted in 6 from 5) + 6 (still 6 but now converted in 7) + 8 (converted 7 to 8) + 9 (converted 8 to 9)

29 is the answer

its 30 in gcc. Try it from right->left order.

yes from right to left it is 30 (6 + 7 + 7 (converted into 8) + 10)
btw can you give me the link to download gcc (I know this is not the right place but I really need it and you are right from right to left your answer is right while in left to right order my answers are right)

just google it.

@ geeksoul Actuallly the answer is 27 on gcc. Regarding GCC go check out this link http://www.mingw.org/category/wiki/download

@sunny210 might be result in gcc is 27 but according to right to left approach 30 is correct while according to left to right approach 29 is the best answer

Its 30. I tried it on gcc before posting it. Can you explain the order of evaluation in which the answer is 27?

@sunny210 thanks for the link :slight_smile:

output be 6

++ is higher precedence than the Plus operator therefore after the increment the value and add the number

modern compiler does not accept these type of formats (++x + ++x).If you use turbo compiler than answer will be 15.

1 Like

For the given code answer should be 5… Because earlier x=3(as per initialisation) Then next operation ++x means that it will increment the value first then it will store ++3 which equals 5 is stored in memory then next operation x++ means it will first store then increment that is 5 will be incremeneted but not stored in the memory. So it gives output 5… Just execute it you will be more clear on my answer.

u r right man…