C supports large set of operators.An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.Operators are used in the programs to manipulate the data and variables.C operators are classified into number of groups.They are
(a) Arithmetic Operators
(b) Relational Operators
(c) Logical Operators
(d) Assignment Operators
(e) Increment and Decrement Operators
(f) Conditional Operators
(g) Bit-wise Operators
(h) Special Operators
Arithmetic Operators:C provides all basic arithmetic operators which include '+','-','*','/','%'.The operators +,-,* and / all work in the same way as in other languages i.e. they perform addition ,subtraction, multiplication and division respectively.These operators can operate on any built-in data types allowed in C.The unary minus operator, in effect, multiplies its single operand by -1.Therefore a number preceded by a minus sign changes it sign.
'+' means addition or unary plus '-' means subtraction or unary minus
'*' means multiplication
'/' means division
'%' means modulo division.Relation Operators:Generally two quantities are often compared with each other and depending on their result certain decisions are taken.These comparisons can be done using
relational operators.C supports six(6) relational operators in all.They are stated as follows:
'<' means
is less than '<=" means
is less than or equal to'>' means
is greater than'>=' means
is greater than or equal to'==' means
is equal to'!=' means
is not equal toLogical Operators:C has the following logical operators.
&& ----> logical
AND| ------> logical
OR! ------> logical
NOTAssignment Operators:Assignment operators are used to assign the result of an expression to a variable.The generally used assignment operator is '='.
Increment & Decrement Operators:The useful operators that are not found in other languages are the increment and decrement operators.The operators are '++' and '--'.
The operator '++' adds 1 to the operand whereas '--' subtracts 1 from the operand.There are two forms that is taken by these operators.They are post & pre increment and decrement operators.Both perform same operation to an operand but they differ when they are assigned to a variable as a statement.The post increment and pre increment of an operand 'm' is
m++;----post increment
++m; --- pre increment
m--;---- post decrement
--m; pre decrement.
x=m++;
This statement assign the value of m to x and later increments the value of 'm'.
x=++m;
This statement initially increments the value of m and later assigns that value to the 'x' variable.
Conditional Operators:A operator pair "?:" is available in C to construct conditional expressions.The general form of conditional expression is
exp1?exp2:exp3;
The operator pair ?: works as follows
-Initially it evaluates the exp1.
-If exp1 is true then exp2 is executed.
-If exp1 is false then exp3 is executed.
Bit-wise Operators:C has special operators for manipulation of data at bit level known as bit wise operators.The various bit wise operators present are
&------bit wise AND|-------bit wise OR^------bit wise exclusive OR<<-----shift left>>-----shift right~-------One's complementSpecial Operators:C supports special operators such as comma operator,
sizeof operator,pointer selection operators(& and *) and member selection operators(. and ->).
The comma operator is used to link the related expressions together.
sizeof operator is a compile time operator and when used with an operand, it returns the number of bytes the operand occupies.The operand may be a variable, a constant or a data type qualifier.pointer operator * is used to access the memory locations value that is stored in the pointer.