Increment and Decrement Operators in COperators are the predefined symbols of the C/C++ library, and it is used to perform logical as well as mathematical operations to the operands. There are various types of operators in the C programming language, such as arithmetic, logical, bitwise, increment or decrement operators, etc. Increment OperatorIncrement Operators are the unary operators used to increment or add 1 to the operand value. The Increment operand is denoted by the double plus symbol (++). It has two types, Pre Increment and Post Increment Operators. Preincrement OperatorThe preincrement operator is used to increase the original value of the operand by 1 before assigning it to the expression. Syntax In the above syntax, the value of operand 'A' is increased by 1, and then a new value is assigned to the variable 'B'. Example 1: Program to use the preincrement operator in C Output Input the value of X: 10 Input the value of Y: 15 Input the value of Z: 20 The updated value of the X: 11 The updated value of the Y: 16 The updated value of the Z: 21 Post increment OperatorThe postincrement operator is used to increment the original value of the operand by 1 after assigning it to the expression. Syntax In the above syntax, the value of operand 'A' is assigned to the variable 'X'. After that, the value of variable 'A' is incremented by 1. Example 2: Program to use the postincrement operator in C Output Input the value of X: 10 Input the value of Y: 15 Input the value of Z: 20 The original value of a: 10 The original value of b: 15 The original value of c: 20 The updated value of the X: 11 The updated value of the Y: 16 The updated value of the Z: 21 Decrement OperatorDecrement Operator is the unary operator, which is used to decrease the original value of the operand by 1. The decrement operator is represented as the double minus symbol (). It has two types, Pre Decrement and Post Decrement operators. Pre Decrement OperatorThe Pre Decrement Operator decreases the operand value by 1 before assigning it to the mathematical expression. In other words, the original value of the operand is first decreases, and then a new value is assigned to the other variable. Syntax In the above syntax, the value of operand 'A' is decreased by 1, and then a new value is assigned to the variable 'B'. Example 3: Program to demonstrate the pre decrement operator in C Output Input the value of X: 5 Input the value of Y: 6 Input the value of Z: 7 The updated value of the X: 6 The updated value of the Y: 7 The updated value of the Z: 8 Post decrement Operator:Post decrement operator is used to decrease the original value of the operand by 1 after assigning to the expression. Syntax In the above syntax, the value of operand 'A' is assigned to the variable 'B', and then the value of A is decreased by 1. Example 4: Program to use the post decrement operator in C Output Input the value of X: 6 Input the value of Y: 12 Input the value of Z: 18 The original value of a: 6 The original value of b: 12 The original value of c: 18 The updated value of the X: 5 The updated value of the Y: 11 The updated value of the Z: 17 Example 5: Program to perform the pre increment and pre decrement operator Output Enter the value of i 5 Enter the value of j 10 After using the preincrementing, the value of i is 6 The value of x is 6 After using the predecrementing, the value of j is 9 The value of y is 9 Example 6: Program to print the post increment and post decrement operator Output Enter the value of i 10 Enter the value of j 20 After using the postincrementing, the value of i is 11 The value of x is 10 After using the postdecrementing, the value of j is 19 The value of y is 20 Difference between the Increment and Decrement Operator in C
Next TopicLogical AND Operator in C
