by Dinesh Thakur Category: Operator

When a division is performed the remainder of the operation is given by modulus operator. The modulus operator is denoted in c by symbol %. Say for instance we have two integer values x and y and then the operation x % y called as x modulus y gives the result as (x- (x / y) * y). Say if x=18 and y =5 the x % y gives value as (18- (18 / 5) * 5) which gives (18-15) which results in 3 in other words the remainder of the division operation.

But there is a restriction in C language while using the modulus operator. There are two types of numerical data types namely integers, floats, double. But modulos operator can operator only on integers and cannot operate on floats or double. If anyone tries to use the modulus operator on floats then the compiler would display error message as ‘Illegal use of Floating Point’.

Let us see this with an example:

main ()

{

float x=7,y=5;

int z;

z = x % y;

printf( %d”, z)’;

}

This above program would give error as ‘Illegal use of Floating Point’.

This is because modulus operator is made to operate on float values namely x and y which is not possible.

About Dinesh Thakur

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article

#### Define Operator, Operand, and Expression in 'C'

#### Which bitwise operator is suitable for checking whether a particular bit is ON or OFF

#### How does the prefix and postfix operator on expression

#### Define different types of Operators.

#### What is the functionality and restrictions of Modulus Operator

#### What is the difference between ++var and var++

#### What is Precedence of Operators

#### Boolean Operators in C

#### Bitwise Operators in C

#### sizeof() operator in C

#### Composite Assignment Operators in C

#### Relational and Equality Operators

#### Arithmetic Operators in C

#### Logical Operators in C

#### What is Operators in C language?

#### What is Precedence and Associativity of Operators?

#### What is Arithmetic operator in C language?

#### What is conditional expression operator(ternary operator)?

#### Assignment Operator in C

#### Const and volatile Qualifiers in C

Basic Courses

Advance Courses