C language supports variety of operators. The different categories of operators supported by C language are as follows.
1) Mathematical/Arithmatic operators
2) Relational operators
3) Logical operators
4) Short-hand assignment operators
5) Increment/decrement operators
6) Conditional operator
7) Bitwise operators
the ÷ operator and % operator are the operators from mathematical operators. ÷ operator is used to obtain quotient and % operator is used to obtain remainder, when one number is divided by another number.
Let us see one example. Below is the program which shows use of ÷ and % operators. In C language ÷(division) operator is shown by / sign and modulus operator is shown by % sign.
Please include and header files before main function.
//PROGRAM TO ILLUSTRATE USE OF DIVISION AND MODULUS OPERATOR.
printf("Enter any two numbers\n");
printf("\nResult of division(a/b)which is quotient is %d",rd);
printf("\nRemainder after division is %d",rr);
Different logical operators are AND(&&), OR(||) and NOT(!) operators. Logical operators AND and OR are used when more than two conditions are required to combine together to get the result.
In case of AND operator, when all the conditions are true then and then only final answer is true.
Let us see one daily life example to understood AND operator. If teacher declared that if Raju and Abhi comes, then I will teach the class. In this case the class will be conducted only when both Raju and Abhi comes. In rest of the cases class will not be conducted.
In case of OR operator, when any one of the condition is true then final answer is true.
Let us see one daily life example to understood OR operator. If teacher declared that if Raju or Abhi comes, then I will teach the class. In this case the class will not be conducted only when both Raju and Abhi did not comes. In rest of the cases class will be conducted.
In case of NOT operator, it changes the current state of variable or expression. If current state of expression/variable is true then after applying NOT operator it changes to false and vice-versa.
if((var=='a')||(var=='e')||(var=='i')||(var=='o')||(var=='u')) is called as logical expression.
Different relational operators are <(less than), >(greater than), <=(less than or equal to), >=(greater than or equal to), ==(comparison). !=(Not equal to).
Normally relational operators are used to check the relation between two entities.
e.g. if Abhay is 17 years college student then to check whether Abhay is eligible for voting or not? we use age>=18 condition. Here age>=18 is a relational expression.
Precedence means priority of operators. Precedence of relational operators is higher than logical operators.