From 97f80c715c4715adeeccd63f6525e6864975a987 Mon Sep 17 00:00:00 2001 From: kzellers Date: Sat, 1 Dec 2018 19:02:30 -0800 Subject: [PATCH] added example for incrementation (#23908) --- guide/english/c/more-math/index.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/guide/english/c/more-math/index.md b/guide/english/c/more-math/index.md index 7f3fa04e67..541ef1a9ce 100644 --- a/guide/english/c/more-math/index.md +++ b/guide/english/c/more-math/index.md @@ -25,7 +25,15 @@ There are a lot of situations where you want to take a number and either go up o 3: a--; 4: --a; ``` -Both the examples at 1 and 2 will increase the value of a by one. Both of the examples at 3 and 4 will decrease the value of a by one. However, 1 does not do quite the same thing as 2, and 3 does not do quite the same thing as 4. Pre-fix operators are called this because the operation is a prefix (2 and 4 are our prefix operators). This acts slightly differently from our post-fix operators at 1 and 3. Pre-fix operators perform the operation, then return the value. Post-fix operators return the value, then perform the incrementation. +Both the examples at 1 and 2 will increase the value of a by one. Both of the examples at 3 and 4 will decrease the value of a by one. However, 1 does not do quite the same thing as 2, and 3 does not do quite the same thing as 4. Pre-fix operators are called this because the operation is a prefix (2 and 4 are our prefix operators). This acts slightly differently from our post-fix operators at 1 and 3. Pre-fix operators perform the operation, then return the value. Post-fix operators return the value, then perform the incrementation. You can see the effects of this difference here: + +```C +int a = 1; +int b = ++a; // b = 2, a = 2 + +int c = 1; +int d = c++; //c = 2, d = 1 +``` ### Unary plus and minus In the normal math you're used to, you use a '-' in front of a number or variable, and that makes the number or variable negative. If the number or variable is already negative, it becomes positive.