-4
#include<stdio.h>
void main()
{
int i=10;
printf("%d %d %d\n",a,--a,++a); // output  10 10 10

}

how this code gives same output? what is the precedence of these increment and decrement operators?

2 Answers2

0

C like many language use Eager evalution (https://en.wikipedia.org/wiki/Eager_evaluation)

This mean the argument of printf are evaluated before the printf function is called.

For the compiler, your code looks like

#include<stdio.h>
void main()
{
  int a=10;
  a;
  --a;
  ++a;
  printf("%d %d %d\n",a,a,a); // output  10 10 10
}
ced_c
  • 149
  • 5
-1

It gives you the same output because - - a print the original value of a and then It became 9 (or 11 with ++a)

Hoffman
  • 72
  • 1
  • 9