Monday, January 25, 2016

C Operators - Arithmetic, Assignment, Relational and Logical

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
ArityDescription
Unary OperatorOperates on single operand.
Binary OperatorOperates on two operands, For example: '/' (used for division).
Ternary OperatorOperates on three operands. Example : conditional operator (we will discuss about it in this chapter).
n-ary OperatorOperators that operate on more than 3 operands.

Types of Operators

Type of OperatorDescription
Arithmetic operatorArithmetic operators are used to perform mathematical operations.
Relational operatorRelational operators are used to perform comparison operations.
Logical operatorLogical operators are used to perform basic operation of boolean algebra ('AND', 'OR', and 'NOT').
Bitwise operatorBitwise operators are used to perform bit wise manipulation on operands.
Assignment operatorAssignment operator is used to assign value of the second operand to first.
Conditional operatorConditional operators operates on a condition and return result based on the truth value of condition.

No comments: