Operators in C
An expression consists of variables and constants separated by operators. C language uses 7 types of operators as listed below:
1. Arithmetic Operators : Arithmetic Operators are used to perform arithmetic operations.
2. Relational Operators : Relational Operators are used to compare the values of operands or expressions to produce a logical value. A logical is either true or false.
|<=||less than or equal to||4<=3||false|
|>=||greater than or equal to||4>=3||true|
|!=||not equal to||4!=3||true|
3. Logical Operators : Logical Operators are used to connect more relational operations to form a complex expression that is called Logical Operators or Logical expression. A value obtained by evaluating a logical expression is always logical either true or false.
|||||logical or||(4<2) || (4>3)||true|
|!||logical not||! (4<2)||true|
4. Increment and Decrement operators (++ and – –) : Increment operator (++) is used to increase the value of an integer or char variable by 1. Decrement operator (- -) is used to reduce the value of an integer or char variable by 1. Consider the following examples :
a = 25;
a++ or ++a will produce the result a = 26
a = 25;
a- – or – -a will produce the result a = 24
5. Assignment Operators : Assignment Operators are used to perform arithmetic operations while assigning a value to a variable.
6. Conditional Operators or Ternary Operators (?:) : Conditional Operators is used to check a condition and select a value depending on the value of the condition. Normally the selected value will be assigned to a variable which has the following form :
7. Bitwise Operators : Bitwise Operators are used to perform operations at binary digit level. These operators are not commonly used and used only in special applications where optimized use of storage is required.
|<<||Shifts the bits to left|
|>>||Shifts the bit to right|
|&||Bitwise logical and|
||||Bitwise logical or|
|^||Bitwise exclusive or|