Firstly, this is my first question here so forgive me for any mistakes.. I came across this program below :
#include<stdio.h>
main()
{
int i=2;
void add();
add(i++,--i);
printf("/ni=%d ",i);
}
void add(int a ,int b)
{
printf("/na=%d b=%d",a,b);
}
The output is :
a=1 b=2
i=2
This is also posted in the below link:
Pre increment and post increment function call
when i did a little experiment, i found out that if you make the declaration "int i;" global,then output changes as:
a=1 b=1
i=2
When i searched for explanation i found out that in function calls the arguments are always pushed in stack from right. That explains the first output but how do you explain second output?
How post incrementation and pre incrementation are evaluated in case the variable is global? Or am I interpreting it all wrong?