Multiplication, Division and ModuloMultiplication, Division and Modulo

Multiplication (*)

The * multiplication operator forms the product of the values on both sides of the "*" sign.

For example, let's calculate how many liters of water we need to completely fill the pool:

c

Main.c

Division (/)

The division operator / divides the right operand's value by the left operand's value.

For example, let's find out the speed of the car:

c

Main.c

The double variables were created to make our answer non-integer and, therefore, more accurate. Otherwise, if we manipulate only integer values, the result will also be an integer:

c

Main.c

Maybe it will work if you change the specifier? – No.

The result will be completely incorrect:

c

Main.c

But there is also a correct calculation option without an additional variable:

c

Main.c

Note

To have a non-integer result, one of the variables must be non-integer.

Modulo (%)

Operator % returns the remainder of the normal division. For example:

c

Main.c

Note

We used the % character twice in a row to warn the compiler that we wanted to use the % character as a string, not as a specifier.

question-icon

What will this expression equal?

Select the correct answer

Everything was clear?

Section 3. Chapter 3