Modifying operators:
- Modify operators also called unary operators.
- Modify operators are Increment and Decrement operators.
- Increment operator increase the value of variable by 1
- Decrement operator decrease the value of variable by 1
Increment operators is of two types
1) pre-increment
2) post-increment
Decrement operators is of two types
1) pre-decrement
2) post-decrement
Expression with modify operators use following steps for evaluation:
- Pre-increment / Pre-decrement
- Substitution of values
- Evaluation based on priorities
- Assignment to variable
- Post-increment / Post-decrement
Execution of Pre-increment operator:
#include<stdio.h>
main()
{
int a=10,b;
b = ++a;
printf("%d,%d",a,b);
}
Execution of Post-increment operator:
#include<stdio.h>
main()
{
int a=10,b;
b = a++;
printf("%d,%d",a,b);
}
If an expression contains both pre-increment and post-increment operators, first pre-increment operators evaluate and the values will be substituted. After execution of expression, the post-increment values will be substituted into variables.
#include<stdio.h>
main()
{
int x=10,y=20,z;
z = x++ * --y ;
printf("%d,%d,%d",x,y,z);
}