In this post we will be going to discuss following queries:
- Increment and Decrement operator in C language
- Pre increment and Post increment operator
- Pre decrement and Post decrement operator
Increment Operator in C:
An increment operator is nothing but, it is type of operator which is used in C language to add 1 to the operand it is represented by '++'.
It basically classified into categories:
- Pre Increment Operator
- Post Increment Operator
Pre Increment Operator in C:
For example:
m=5;
y=++m;
Here you can observe that increment symbol is use before the operands m,Such condition are know as pre increment operator.In this case the value of Y and M would be 6.This is because in case of pre increment operator first add 1 to the operands and then the result is assigned to the variable on left.
Post Increment Operator in C:
For example:
m=5;
y=m++;
Here you can observe that increment symbol is use after the operands m,Such condition are know as post increment operator.In this case y would be 5 and m would be 6.This is because in case of post increment operator first assign the value to the variable on left and then increment the operands.
Decrement Operator in C:
A decrement operator is used in C language to subtract from the operand it is represented by '--'.
It is also classified into two categories:
- Pre Decrement Operator
- Post Decrement Operator
Pre Decrement Operator in C:
For example:
m=5;
y=--m;
Here you can observe that decrement symbol is use before the operands m,Such condition are know as pre decrement operator.In this case the value of Y and M would be 4.This is because in case of pre decrement operator first subtract 1 from the operands and then the result is assigned to the variable on left.
Post Decrement Operator in C:
For example:
m=5;
y=m--;
Here you can observe that decrement symbol is use after the operands m,Such condition are know as post decrement operator.In this case y would be 5 and m would be 4.This is because in case of post decrement operator first assign the value to the variable on left and then decrement the operand.
Conclusion:
In this article we have learned about Increment and Decrement operator in C language, Pre increment and Post increment operator, Pre decrement and Post decrement operator in detail I hope you have no any doubt left related to this topic but if you have any still remain then feel free comment below.
