Arithmetic operators in c

Arithmetic operators in c

The Arithmetic operators are used for numerical calculations such as addition, subtraction, multiplication, division etc

1. Unary arithmetic operators
2. Binary arithmetic operators

Unary arithmetic operators

The unary operators are required only one operand. See in the below example

++x, –y, x++, y–

Binary Arithmetic operators in C

The binary operators require two operands So there are five binary operators in c. show in the below

Serial no. Operator Purpose
1. + Addition
2. Subtraction
3. * Multiplication
4. / Division
5. % Modular

% is modular operator which gives the remainder of the integer. modular operator can not apply with floating point operands. here is one thing Note that unary minus and plus operators are different from the addition and subtraction operators. When both operands are integers, then the resulting value always will be integer let us take example there are two operands x is 19 and y is 8, then the result of the following operations are-

Expression Result
x+y 27
x-y 11
x*y 152
x/y 2(decimal part remove)
x%y 3(remainder after integer division)

in the above example in the division operation the decimal part will be truncated then the result will be only integer part of quotient.after modular operation in the result the remainder part of integer division. in the modular operation the second operand must be non zero for modular and division operations.

/* Integer arithmetic operations*/
#include< stdio.h >
void
main()
{
int x=19,y=8;
printf(“subtraction is=%d”,x-y);
printf(“\n addition is =%d”,x+y);
printf(“\n multiplication is =%d”,x*y);
printf(“\n division is =%d”,x/y);
printf(“\n remainder is =”,x%y);
}

output: subtraction is=11
addition is =28
multiplication is =152
remainder is =3