Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Sum, Difference, Increment, Decrement | Operators
C Basics

Sum, Difference, Increment, Decrement

Addition Operator (+)

The + operator adds the values on either side of it.

You can also use variables in place of direct values.

c

Main.c

Note

While some programming languages allow you to concatenate strings using the + operator, like "Hell" + "o" = "Hello", C does not.

Subtraction Operator (-)

The subtraction operator, -, calculates the difference between the values on either side of it.

c

Main.c

You can also use the - sign to convert positive values to their negative counterparts.

c

Main.c

Increment Operator (++)

The increment operator, ++, was introduced to simplify code readability.

This operator adds 1 to a value, and it's commonly used in loops. The example above illustrates the most basic use of the operator.

Decrement Operator (--)

Conversely, the decrement operator, --, subtracts 1 from a value:

Pre vs. Post Increment

Increment and decrement operators come in two forms:

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

The distinction lies in the values they return:

OperatorUsageDescription
++a++Increments a by 1 but returns its original value
++++aIncrements a by 1 and returns its incremented value
----aDecreases a by 1 and returns its decremented value
--a--Decreases a by 1 but returns its original value
c

Main.c

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

Select the correct answer

Everything was clear?

Section 3. Chapter 2
course content

Course Content

C Basics

Sum, Difference, Increment, Decrement

Addition Operator (+)

The + operator adds the values on either side of it.

You can also use variables in place of direct values.

c

Main.c

Note

While some programming languages allow you to concatenate strings using the + operator, like "Hell" + "o" = "Hello", C does not.

Subtraction Operator (-)

The subtraction operator, -, calculates the difference between the values on either side of it.

c

Main.c

You can also use the - sign to convert positive values to their negative counterparts.

c

Main.c

Increment Operator (++)

The increment operator, ++, was introduced to simplify code readability.

This operator adds 1 to a value, and it's commonly used in loops. The example above illustrates the most basic use of the operator.

Decrement Operator (--)

Conversely, the decrement operator, --, subtracts 1 from a value:

Pre vs. Post Increment

Increment and decrement operators come in two forms:

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

The distinction lies in the values they return:

OperatorUsageDescription
++a++Increments a by 1 but returns its original value
++++aIncrements a by 1 and returns its incremented value
----aDecreases a by 1 and returns its decremented value
--a--Decreases a by 1 but returns its original value
c

Main.c

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

Select the correct answer

Everything was clear?

Section 3. Chapter 2
some-alt