Expressions consist of constants and variables combined together with operators. Five types of operators are used in C language which are:
There are two precedence levels for these arithmetic operators. The high priority operators are “*” and “%” and the low priority operators are “+” and“–”. When an expression containing several of these operators is evaluated, all high priority operations are performed first in the order in which they occur, from left to right and then all low priority operations are carried out in the order in which they occur.
Assignment Operators:
The basic assignment operator is "=". This is used to assign value of an expression to variable. It has the general form:
- Arithmetic Operators
- Assignment Operators
- Relational Operators
- Logical Operators
- Increment/Decrement Operators
There are two precedence levels for these arithmetic operators. The high priority operators are “*” and “%” and the low priority operators are “+” and“–”. When an expression containing several of these operators is evaluated, all high priority operations are performed first in the order in which they occur, from left to right and then all low priority operations are carried out in the order in which they occur.
Assignment Operators:
The basic assignment operator is "=". This is used to assign value of an expression to variable. It has the general form:
variable = expression
When expression may be a constant, another variable is to which a value has previously been assigned or a formula to be solved.
sum = 1 =b;
In addition to "=", there are a number of assignment operators unique to C language. If “OP” represents any of these operators then
variable op = expression
Relational Operators:
Relational operators are used to compare two values of the same type. In C, there are six types of relational operators are used. These are:
- Equal To ( = )
- Not equal to ( != )
- Less than ( < )
- Greater than ( > )
- Less than or equal to ( <=)
- Greater than or equal to ( >= )
In C, true is represented by the integer 1 and false is represented by the integer “0”. In some languages true and false values are represented by a special type of variable type called “Boolean”. There is no such data type in C language, so true and false are represented by integers 1 and 0
Logical Operators:
These operators are used for forming compound conditions from simple ones. There are three types of logical operators in C.
- Not ( ! )
- And ( && )
- Or ( I I )
Increment/Decrement Operators:
There are two types of Inc/Dec operators are used in C language. These are :
- Increment by 1 ( ++ )
- Decrement by 1 ( -- )
a = ++a;
First increments a and then assign the value 2 to a. But the statement
a = a++;
First assign the value 3 to a and then increments a to 2. In both cases a is assigned the value to 2.
Post a Comment