Increment operator:
Increment operator (++) is a unary operator. It operates on one operand. It is used to add one to an existing value of variable.
Syntax: variable_name++ or ++variable_name
Example:
int num=6;
printf(“%d”,num);
num++;
printf(“\n%d”,num);
In above example initially value of num is 6. Due to increment operator (++) value of variable num will become 7.
Decrement operator:
Decrement operator(--) is an unary operator. It operates on one operand. It is used to subtract one from an existing value of variable.
Syntax: variable_name-- or --variable_name
Example:
int num=5;
printf(“%d”,num);
num--;
printf(“\n%d”,num);
In above example initially value of num is 5. Due to decrement operator (--) value of num will become 4.
0 Comments