Possible Duplicate:
Post Increment and Pre Increment concept?
I cant understand how the “if condition” works with the increment/decrement operator in this scenario:
#include<stdio.h>
void main()
{
int n=0;
if(n++)
{
printf("C-DAC");
}
else if(n--)
{
printf("ACTS");
}
}
Its output is ACTS.
what is happening in the IF condition?
if (n++)It checks ifnis not equal to zero and then incrementsnelse if (n--)It checks ifnis not equal to zero and then decrementsnYour first
ifstatement is not true (becausenis zero), thennis incremented, andelse ifstatement is checked (nis equal to 1 at this point),if (1)is true andprintf("ACTS")is called