Technologies

C

Increment and Decrement in C Language
(adsbygoogle = window.adsbygoogle || []).push({});
# Increment and Decrement Operators :

**Note : **

Increment and Decrement operators can not be applied on floating points.
**Examples : **
(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});

CLanguage

Friday, 31 Mar 2017

134

0

0

Increment Operator is represented by ++. It increment the operand by 1.

Decrement Operator is represented by --. It decrements the operand by 1.

Operator |
Meaning |
---|---|

a++ | post-increment |

++a | pre-increment |

a-- | post-decrement |

--a | pre-decrement |

Increment and Decrement operators can not be applied on floating points.

Rules for ++ and -- operators :

- Increment and Decrement operators are unary operators and require variables as operands.
- When postfix ++ (or --) is used with a variable in an expression, the expression is evaluated first using the original value of the variable and then the variable is incremented (or decremented) by one.
- When prefix ++ (or --) is used with a variable in an expression, the variable is incremented (or decremented) first and then the expression is evaluated using the new value of the variable.
- The precedence and associativity of ++ and -- operators are the same as those of unary + and unary -.

We use the increment and decrement statements in for and while loops extensively. These two operators are unary operators, they operate on only one operand.

They follow right to left associativity.

1. post - increment :

int a = 8;

y = a++;

The value of y will be 8.

2. pre - increment :

int a = 8;

y = ++a;

The value of y will be 9.

3. post - decrement :

int a = 5;

y = a--;

The value of y will be 5.

4. pre - decrement :

int a = 5;

y = --a;

The value of y will be 4.

int a = 8;

y = a++;

The value of y will be 8.

2. pre - increment :

int a = 8;

y = ++a;

The value of y will be 9.

3. post - decrement :

int a = 5;

y = a--;

The value of y will be 5.

4. pre - decrement :

int a = 5;

y = --a;

The value of y will be 4.

Post Article

Upload Youtube Video

CLanguage

Friday, 31 Mar 2017

134

0

0

Popular Post

- Write an algorithm and draw the flowchart to find the largest number among the three numbers?
- Write an algorithm an draw flowchart to find factorial of a number?
- Write an algorithm and draw the flowchart to find whether a given number is even or odd?
- Write an algorithm and draw the flowchart to Swap two integers?
- Write an algorithm an draw the flowchart to compute the average of the three numbers?
- Write an algorithm and draw the flowchart to find the largest number amoug two numbers?
- write a c program to swap two numbers
- How to write a algorithm?
- What is mean by Operator Precedence and Associativity in C Language?
- C Languages Relational Operators

© 2019 - technotecode. All contents are copyright of their authors