Program for Increment & Decrement Operators
Increment operators are divided into 2 types(++).
* post increment.
a++;
The original value of 'a' is assigned to 'a' first,increment
(+1) to the next operation.
* pre increment.
++a;
The incremented value(+1) is assigned first,after perform the
operation.
example1 :-
#include<stdio.h>
main()
{
int a =6;
clrscr();
printf("y=%d",y++);
getch();
}
example2 :-
#include<stdio.h>
main()
{
int x =10;
clrscr();
printf("value of x =%d",x++);
printf("value of x =%d",--x);
printf("value of x =%d",x--);
printf("value of x =%d",++x);
printf("value of x =%d",x++);
getch();
}
example3 :-
#include<stdio.h>
main()
{
int x =6;
clrscr(); printf("%d%d%d",x++,++x,x--);
getch();
}
example4 :-
#include<stdio.h>
main()
{
int i,j =4;
clrscr();
i =j++ * ++j * j--; printf("\ni=%d,j=%d",i,j);
getch();
}
0 comments:
Post a Comment