#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?
#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?
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
}
It gives you the same output because - - a print the original value of a and then It became 9 (or 11 with ++a)