An operator is a symbol that helps us to perform specific mathematical and logical computation operation on a value or a variable.
There are following types of operators to perform different types of operations in C language.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Other Operators
An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc
|+||Adds two operands.||A + B = 30|
|−||Subtracts second operand from the first.||A − B = -10|
|*||Multiplies both operands.||A * B = 200|
|/||Divides numerator by de-numerator.||B / A = 2|
|%||Modulus Operator and remainder of after an integer division.||B % A = 0|
|++||Increment operator increases the integer value by one.||A++ = 11|
|—||Decrement operator decreases the integer value by one.||A– = 9|
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.
Relational operators are used in decision making.
|Operator||Meaning of Operator||Example|
|!=||Not equal to|
|>=||Greater than or equal to|
|<=||Less than or equal to|
Logical operators are used in decision making in C programming. An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false.
|&&||Called Logical AND operator. If both the operands are non-zero, then the condition becomes true.||(A && B) is false.|
|||||Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true.||(A || B) is true.|
|!||Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.||!(A && B) is true.|
The Bitwise operators is used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands.
|Operators||Meaning of operators|
|^||Bitwise exclusive OR|
Assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value.
sizeof () and Ternary operators, Comma Operator.
sizeof() is a unary operator that returns the size of data (constants, variables, array, structure, etc.
Comma acts as both operator and separator.comma operator has the lowest precedence of any C operator. Comma operators are used to link related expressions together.
&:- Returns the address of a variable.
Ternary operators / Conditional Operator- ?
Operators Precedence in C
|Postfix||()  -> . ++ – –||Left to right|
|Unary||+ – ! ~ ++ – – (type)* & sizeof||Right to left|
|Multiplicative||* / %||Left to right|
|Additive||+ –||Left to right|
|Shift||<< >>||Left to right|
|Relational||< <= > >=||Left to right|
|Equality||== !=||Left to right|
|Bitwise AND||&||Left to right|
|Bitwise XOR||^||Left to right|
|Bitwise OR|||||Left to right|
|Logical AND||&&||Left to right|
|Logical OR||||||Left to right|
|Conditional||?:||Right to left|
|Assignment||= += -= *= /= %=>>= <<= &= ^= |=||Right to left|
|Comma||,||Left to right|