Skip to content

Latest commit

 

History

History
10 lines (5 loc) · 987 Bytes

File metadata and controls

10 lines (5 loc) · 987 Bytes

What is the difference between "++i" and "i++" in C programming?

In C programming, "++i" and "i++" are both increment operators, but they behave differently.

"++i" is called the pre-increment operator. It increments the value of "i" by 1 before using it in the expression. For example, if "i" is initially 5, the expression "++i + 2" would result in 8 because "i" is first incremented to 6, and then added to 2.

On the other hand, "i++" is called the post-increment operator. It increments the value of "i" by 1 after using it in the expression. For example, if "i" is initially 5, the expression "i++ + 2" would also result in 7, because "i" is first used in the expression (which evaluates to 5 + 2), and then incremented to 6.

So, the main difference between the two is the order in which the increment operation occurs in the expression. "++i" increments before the expression is evaluated, while "i++" increments after the expression is evaluated.