Operator Basics
Operators in C language are symbols which tells the compiler to perform some mathematical calculations or logical operations (we will look at in a while) on the variables and constants. For example, consider the mathematical operation "
10 + 2 - a"
. Here '+' and '-' are called operators and the values on which operators work ('10', '2', and 'a') are known as operands. C programming language has wide variety of operators which are categorised into different groups based on the type of operations they perform.Operator Arity
Arity implies the number of operands the operator is defined to work on. Based on that we have operators of following articles
Arity | Description |
---|---|
Unary Operator | Operates on single operand. |
Binary Operator | Operates on two operands, For example: '/' (used for division). |
Ternary Operator | Operates on three operands. Example : conditional operator (we will discuss about it in this chapter). |
n-ary Operator | Operators that operate on more than 3 operands. |
Types of Operators
Type of Operator | Description |
---|---|
Arithmetic operator | Arithmetic operators are used to perform mathematical operations. |
Relational operator | Relational operators are used to perform comparison operations. |
Logical operator | Logical operators are used to perform basic operation of boolean algebra ('AND', 'OR', and 'NOT'). |
Bitwise operator | Bitwise operators are used to perform bit wise manipulation on operands. |
Assignment operator | Assignment operator is used to assign value of the second operand to first. |
Conditional operator | Conditional operators operates on a condition and return result based on the truth value of condition. |
No comments:
Post a Comment