0

Hi I'm new to C programming. It's been 2 weeks since I started learning C. I came across Increment and Decrement Operators and made some changes. Here's my coding-

#include <stdio.h>
int main ()
          {
           int a = 6, b;
           printf("%d", b = a+ ++a);
           return 0;
          }

The result came 14.

I think b = 6 + (now a is increased to 7) b = 6 + 7 = 13

Pls explain where I'm wrong.

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • 1
    You are wrong only in assuming that the expression `a + ++a` has a defined meaning that can be figured out, by you or anybody. It does not. It has no defined meaning. So don't worry about it, other than to take care that you don't write meaningless expressions like that in your C programs. The answers at [the linked question](https://stackoverflow.com/questions/949433) can help you learn why this particular expression is undefined, and how you can avoid writing undefined expressions like it. – Steve Summit Nov 22 '21 at 04:11
  • @SteveSummit Thanks for the reference! I have now understood it. – ANDY WANG Nov 22 '21 at 05:51

0 Answers0