-5

I've been trying to understand how the increment and decrement operators works in C language. I didn't get it how to evaluate the output of the specific lines of codes.

The C language code is

int x=5, y; y = ++x * x++;

after executing these two lines, what will be the value of y? On running the code, it gives the output as 49. I can't get it how it get 49?! Any explanations?

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
AD17
  • 1
  • 1
    Undefined behavior is undefined. – David Schwartz Aug 28 '23 at 18:48
  • 1
    Wonder why there are so many questions like that. Who write code like that? – Jarod42 Aug 28 '23 at 19:01
  • @Jarod42 Most probably because people are not being taught to use `-Wall` when they compile :) – Ted Lyngmo Aug 28 '23 at 19:23
  • *after executing these two lines, what will be the value of y?* -- If your teacher gave you this question as homework, they wasted your time. They could have easily explained in less than a minute that the code is undefined behavior, thus do not write code this way. – PaulMcKenzie Aug 28 '23 at 19:34

0 Answers0