Sitemap

Arithmetic Operators in C

2 min readJan 15, 2023

--

Watch the video here or on youtube

In this article, we will discuss the arithmetic operators that are available in the C programming language. We will look at each operator and explore how it is used.

The Addition Operator (+):

The addition operator is used to add two numbers together. The syntax for using the addition operator is as follows:

int total = 5 + 7; // This will assign the value 12 to total.

The Subtraction Operator (-):

The subtraction operator is used to subtract one number from another. For example, if we want to subtract 2 from 9, we would use the following code:

int difference = 9–2; // This will assign the value 7 to difference.

Get Daniel Mbedobe K.’s stories in your inbox

Join Medium for free to get updates from this writer.

Here are examples to show how the multiplication and division operators are used in mathematical operations:

//multiplication operator
int length = 4, width = 3, total;
total = length * width;
printf("%d", total);

//division operator
double qty = 24, students = 5, res;
res = qty / students;
printf("%lf", res);

When using the division operator, remember to use either double or float data types. Using int will return a single-digit result.

Modulo Operator (%):

This operator will return the remaining value of a division. For example, in this block of code, the program will output 4 as the result of the operation.

int x= 24, y= 5, res;
res = x % y;
printf("%d", res); //res = 4

Increment and Decrement Operators (++ / --):

When we use these operators, the result is going to be either an increase or a decrease in the value assigned to the variable. For example:

int size = 65;

printf("%d", ++size); //size = 66

printf("%d", --size); //size = 64

And that is how we use arithmetic operators to perform mathematical operations in C programming.

--

--

Daniel Mbedobe K.
Daniel Mbedobe K.

Written by Daniel Mbedobe K.

Frontend Developer and Data Analyst. Open to work as freelancer to design and develope websites and also perform data analysis tasks.