Wednesday, October 9, 2013

Program to show working of Post/Pre Increment/Decrement operator (Unary Operator)



#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
clrscr();
x=5;
y=6;
z=x++;
printf("\n%d - %d", x , z);        //Answer=6 - 5
z=++x;
printf("\n%d - %d", x , z);        //Answer=7 - 7
z=y--;
printf("\n%d - %d", y , z);        //Answer=5 - 6
z=--y;
printf("\n%d - %d", y , z);        //Answer=4 - 4
z=(x++) + (y++);
printf("\n%d - %d - %d" , x , y , z);      //Answer=8 – 5 – 11
getch();
return 0;
}

No comments:

Post a Comment