Important Notice:

Course Content
Building IoT Applications (Chapter-4) M4-R5.1
About Lesson

Increment and Decrement Operators /Unary Operators:

                  Unary operators are having higher priority than the other operators. Unary operators, meaning they only operate on a single operand.

Increment Operator in C Programming

             i. Increment operator is used to increment the current value of variable by adding integer 1.

           ii. Increment operator can be applied to only variables.

           iii. Increment operator is denoted by ++.

We have two types of increment operator i.e Pre-Increment and Post-Increment Operator.

Pre-Increment

          Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.

b = ++y;

In this example suppose the value of variable „y‟ is 5 then value of variable „b‟ will be 6 because the value of „y‟ gets modified before using it in a expression.

Post-Increment

           Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.

b = x++;

In this example suppose the value of variable „x‟ is 5 then value of variable „b‟ will be 5 because old value of „x‟ is used.

The syntax of the operators is given below.

++<variable name>,  –<variable name>

<variable name>++,  <variable name>–

The operator ++ adds 1 to the operand and – subtracts 1 from the operand. These operators in two forms : prefix (++x) and postfix(x++).

 

Operator

Meaning

++x

Pre increment

–  -x

Pre decrement

x++

Post increment

x- –

Post decrement

error: Content is protected !!