Sum, Difference, Increment, DecrementSum, Difference, Increment, Decrement

Sum operator (+)

The addition operator + sums the values on both sides of the + sign.

For example:

Instead of any values, you can use variables:

c

Main.c

Note

In some programming languages, it is possible to sum strings, for example, "Hell" + "o" = "Hello", but not in C.

Difference operator (-)

The - difference operator forms the difference between the values on both sides of the - sign.

For example:

c

Main.c

You can use the - sign to change positive values to negative values.

c

Main.c

Increment operator (++)

The increment operator was created to make the code easier to read.

This operator means +1 and is typically used in loops. This is the simplest form of using this operator.

Decrement operator (--)

The decrement operator, on the other hand, means -1:

Post and Prefix Increment

Increment and decrement have two forms:

  • prefix (++a);
  • postfix (a++).

They differ in that they return different values.

OperatorExpression exampleDescription
++a++increments a by 1 and return the old value
++++aincrements a by 1 and return the new value
----bdecrements b by 1 and return the new value
--b--decrements b by 1 and returns the old value
c

Main.c

question-icon

If b equals 7, what b++ equals to?

Select the correct answer

Everything was clear?

Section 3. Chapter 2