One reason for the power of C is its wide range of useful operators. An operator is a function that is applied to values to give a result. You should be familiar with operators such as +,-,/. Arithmetic operators are the most common. Others operators are used for comparison of values, a combination of logical states, and manipulation of individual binary digits.
An operator is a symbol that represents a particular operation that can be performed on some data. The data is called an operand. The operator thus operates on an operand. Operators could be classified as “unary”, “binary” or “ternary” depending on the number of operands i.e, one, two or three respectively.
- Unary expression: A unary expressionT contains one operand and a unary operator. Binary expression.
- A binary expression: contains two operands separated by one operator.
What is Operators
C is rich in data types, same as C is rich in Operator. From every Operator, C-expression can be defined. By using some Operators we can solve or compute a formula, we can compare two expressions or variable value, or can create a logical relationship between the compound statements, can solve a conditional expression, can do low-level programming and special types of Operators.
Mainly Operators are used to operate two or more than two operands depending upon their processing and given conditions. The relationship of operator with the operands is shown as in the below common statement:
Operand1 Operator Operand2
Or
Operand1 Operator Operand2 Operator Operand3
Here Operand1, Operands, Operand3 may be variable, a constant, or an expression, etc. There are mainly eight operators used in C-Language.
The list of various operators as shown above are described in details as:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Increment/Decrement Operators
- Conditional Operators or Ternary Operators
- Bitwise Operators
- Special Operators
Arithmetic Operators
Arithmetic Operators are used for arithmetic operations like Addition Subraction, Multiplication, Division etc. Mostly arithmetic operators are used in the all the computer languages. There are five arithmetic operators used in C-language. These all are given in the table below:
Operator | Meaning |
---|---|
* | multiplication |
/ | division |
% | modulus (remainder after division) |
+ | addition |
– | subtraction |
For example, Suppose a & b are two variables, then arithmetic operators used for different operations as:
a*b | (multiplication of a with b) |
---|---|
a/b | (division of a by b) |
a%b | (to find module of a with b) |
a+b | (addition of a and b) |
a-b | (subtraction of b from a) |
Relational Operators
These operators are used to create logical relationship between two operands. Relational operators are used for comparison purpose. The expression having two operands and one relational is called Relational Expression. There are mainly six relational operators used in the C-Language. These all are given in the table as:
Operator | Meaning |
---|---|
< | less than |
<= | less than and equal to |
> | greater than |
>= | greater than and equal to |
== | equal to |
!= | not equal to |
For example, Suppose a & b are two variables, If a=5 and b=2 are two integer type variables then some relational expressions using the relational operations are:
a | TRUE |
---|---|
a<=b | TRUE |
a>b | FALSE |
a>=b | FALSE |
a==b | FALSE |
a!=b | TRUE |
Logical Operators
Logical operators are used for logical operations. These operations are used for compound relational expressions or logical expressions. When more than one relational expression occurs in a C expression using logical operators, then such types of expressions are called Compound Relational Expressions or Logical expressions. These are used in decision-making statements and some looping statements like if, switch, do-while, while and for, etc. These statements have either a True (1) branch or false (0) branch. There are mainly three logical operators used in C language as in the table below:
Operator | Meaning | Priority |
---|---|---|
! | Logical NOT (Not process the condition) | Highest |
|| | Logical OR (Process any one of the conditions.) | Intermediate |
&& | Logical AND (Process two or more than two relational expressions) | Lowest |
Assignment Operators
Assignment operators are used for assigning an expression or value (constant) to a variable. Assignment operators are further subdivided into two types:
- Simple Assignment Operator
- Short hand Assignment Operator or Arithmetic Assignment Operator
The general syntax:
v= constant value or variable or expression;
Where v is the variable and expression be any arithmetic expression. for example:
sum = 0; i = 1 a = b;
Shorthand Assignment:
R i+= 1; p*= a-b; l/=1;
Conditional Operators
Conditional Operators are aslo called ? : operators or ternary operator. These operators are used instead of block if statement. The general syntax of conditional operator are as:
exp1 ? exp2 : exp3;
For example:
c =(a>b) ? a-b :a + b;
Increment/Decrement Operators
These operators are also sometimes called special operators or unary special operators. Another name or Increment/Decrement Operators is Counter Operator. These are two as: ++ (increment operator) and — (decrement operator). Increment operators are used for incrementing the value one by one. Similarly decrement operator are used for decrementing the value one by one. These are further sub-divided into two categories:
- Prefix Increment / Decrement Operator
- Postfix Increment / Decrement Operator
Prefix Operator
In the Prefix increment operator, first of all, the value will be increment and the incremented value will be assigned to a variable. Similarly in the prefix decrement operator first of all value will be decrement and then decremented value be assigned to the variable. The general way is represented as:
++v; --v;
Postfix Operator
In the postfix increment operator, first of all value will be assigned to a variable and then it will be incremented. Similarly in the postfix decrement operator first of all value will be assigned and then it will be decremented. The general way is represented as:
v++; v--;
Bitwise Operators
These are special operators for low level programming. These operators are used for the manipulation of binary data (bits). Ther are six types of Bitwise Operator. The table for Bitwise Operators is as:
Operator | Meaning |
---|---|
& | Bitwise AND |
| (pipe symbol) | Bitwise OR |
^ | Bitwise exclusive OR |
<< | Bitwise left |
>> | Bitwise right |
~ (tilde) | Bitwise NOT (complement operator) |
Special Operators
These are used for special purposes in C-language. These operators are used in pointers, structures and unions etc. Some types of special operators are as:
- Unary Operator
- Comma Operator
- Sizeof Operator
- Type Operator
- Pointer Operator
- Member Selection Operator