Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Multiplication, Division and Modulo | Operators
C Basics

Multiplication, Division and ModuloMultiplication, Division and Modulo

Multiplication Operator

The multiplication operator * yields the product of its operands. For instance, if you're trying to determine the amount of water required to fill a pool:

c

Main.c

Division Operator

The division operator / divides the left operand by the right one.

Suppose you want to calculate a car's speed:

c

Main.c

Using double variables ensures our result can be a decimal value, providing a more accurate answer. If we only worked with integer types, the result would also be an integer:

c

Main.c

It's important to note that merely changing the format specifier won't fix an incorrect integer division:

c

Main.c

However, there's a way to get a correct division without introducing another variable:

c

Main.c

Note

For a division to yield a decimal result, at least one of the operands should be of a decimal type like double.

Modulo Operator

The % operator returns the remainder of a division. For instance:

c

Main.c

Note

If you're trying to display the % character in a string (e.g., in a printf statement), you'd use %% to represent a single %. This tells the compiler you want to print the % character and not use it as a format specifier.

So, what's the value of the given expression?

Select the correct answer

Everything was clear?

Section 3. Chapter 3
course content

Course Content

C Basics

Multiplication, Division and ModuloMultiplication, Division and Modulo

Multiplication Operator

The multiplication operator * yields the product of its operands. For instance, if you're trying to determine the amount of water required to fill a pool:

c

Main.c

Division Operator

The division operator / divides the left operand by the right one.

Suppose you want to calculate a car's speed:

c

Main.c

Using double variables ensures our result can be a decimal value, providing a more accurate answer. If we only worked with integer types, the result would also be an integer:

c

Main.c

It's important to note that merely changing the format specifier won't fix an incorrect integer division:

c

Main.c

However, there's a way to get a correct division without introducing another variable:

c

Main.c

Note

For a division to yield a decimal result, at least one of the operands should be of a decimal type like double.

Modulo Operator

The % operator returns the remainder of a division. For instance:

c

Main.c

Note

If you're trying to display the % character in a string (e.g., in a printf statement), you'd use %% to represent a single %. This tells the compiler you want to print the % character and not use it as a format specifier.

So, what's the value of the given expression?

Select the correct answer

Everything was clear?

Section 3. Chapter 3
some-alt