Increment and Decrement Operators, C Language Assignment Help

Assignment Help: >> Operators >> Increment and Decrement Operators, C Language

Increment and Decrement Operators

 C has two very useful operators not generally found in other languages; these are increment and decrement operators ++ and --. They are unary operators. The operand has to be a variable and not a constant. Thus, the expression a++ is valid whereas 6++ is invalid. The use of these operators results in incrementing or decrementing the value of a variable by one.

These operators can be used either in prefix (before the variable) or postfix (after the variable) format. In the case of isolated increment or decrement operation both the format have the same effect and give the same result. Thus, a++ or b-- has the same effect as ++a or --b results respectively. However, prefix and postfix have the different effects when used in association with some other operator or expression in a C statement. When the prefix format of increment or decrement operator is used in association with other operator or expression, the value of the operand is altered before used for other operator or in expression. When these operators are used in postfix format in an associated C statement, the value of operand is altered after used for other operator or in expression.

Example:

                b = ++ a;               (a =a + 1; b = a)

                b = a ++;               (b = a; a = a + 1)

Note: The increment and decrement operators cannot only be used in association with an assignment (=) operator, but also with any other operator and even with printf ().

A prefix operator first adds 1 to the operand and then the result is assigned to the variable on left. On the other hand, postfix operators first assigns the value to the variable on left and then increment the operand. The precedence and associativity of ++ and -- operators are the same as those of unary + and unary -.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd