An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.
Operators usually form a part of the mathematical or logical expressions.
Arithmetic Operators
|
Arithmetic operators are used to perform common mathematical operations (such as - Addition, Substraction, Multiplication, Division).
|
Operators |
Name |
Description |
Example |
+ |
Addition |
Add together two values |
x + y |
- |
Substraction |
Subtracts one values from another |
x - y |
* |
Multiplication |
Multiples two values |
x * y |
/ |
Division |
Divides one value by another |
x / y |
% |
Modulus |
Returns the division remainder |
x % y |
++ |
Increment |
Increases the value of a variable by 1 |
++x |
-- |
Decrement |
Decreases the value of a variable by 1 |
--x |
|
|
Integer Arithmetic – |
If both the operands in a single arithmetic expression such as a + b are integers, the expression is called an integer expression.
|
Real Arithmetic – |
An arithmetic operation involving only real operands is called real arithmetic.
A real operand may assume values either in decimal or exponential notation.
|
Mixed-mode Arithmetic – |
If one of the operands is real and the other is integer, the expression is called a mixed mode arithmetic expression.
If either operand is of the real type, then only the real operation is performed and the result is always a real number.
|
|
Relational Operators
|
Relational Operators are the type of Operators used in a programming language that helps us compare any two entities, like two entities, like two integers, characters, and many more.
|
They always give the result in 1 and 0 where:
1 means that the comparison is True
0 means that the comparison is False
|
Operators |
Name |
Description |
== |
Equality Operator |
This relational operator tests the equality relation between two operands and return 1 if both are equal otherwise return 0. |
!= |
Inequality Operators |
This operator tests the inequality between two operands and returns 1 if both are not equal otherwise return 0.
This is the opposite of equality operator
|
< |
Less Than |
This operator tests that if one value strictly less than the other or not and returns 1 if the first value is less then second otherwise return 0. |
> |
Greater than |
This operator tests than if one value is strictly greater than the other one or not and return 1 if the first value is strictly greater otherwise return 0. |
<= |
Less than or Equal to |
This operator tests that if one value is less than or equal to the other one or not and return 1 if the first value is less than or equal to second value otherwise return 0. |
>= |
Greater than or Equal to |
This operator tests that if one value is greater than or equal to the other one or not and returns 1 if the first value is greater than equal to second value otherwise return false. |
|
|
Logical Operators
|
Logical operators are specially used when we are going to combine two or more conditional and relational expressions. |
Operators |
Name |
Description |
&& |
Logical AND |
Returns 1 if both statements are true |
|| |
Logical OR |
Returns 1 if one of the statements is true
|
! |
Logical NOT |
Reverse the result, returns 0 if the result is 1 |
|
|
Increment and Decrement Operators
|
C allow two useful operators. These are:
Operators |
Name |
Description |
++ |
Increment Operator |
adds 1 to operands |
-- |
Decrement Operator |
subtract 1 from operands |
|
Both are unary operators |
|
|
|
|
|
Conditional Operators
|
A ternary operator pair “ ? : ” is available in C to construct condition expressions of the form. |
Where:
exp1, exp2, and exp3 |
are expressions when using conditional operator
if exp1 is true then exp2 is executed
else if exp1 is false than exp3 is executed.
|
|
|
|
|
Bitwise Operators
|
- Bitwise operators are used for manipulation of data at bit level.
- These operators are used for testing the bits, or shifting them right or left.
- Bitwise Operators may not be applied to float or double.
|
Operators |
Name |
& |
bitwise AND |
| |
bitwise OR |
^ |
bitwise exclusive OR (XOR) |
<< |
Shift Left |
>> |
Shift Right |
~ |
One,s complement Operator
(unary operator) |
|
|
|
|
Special Operators
|
C special operators are:-
- Comma operator
- Size of operator
|
Comma Operator
- The comma Operator can be used to link the related expressions are together.
- Expressions are evaluated left to right.
- The value of right-most expression is the value of the combined expression.
Sizeof Operator
- The sizeof is a compiler time operator.
- When sizeOf used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, a constant, or a datatype qualifier.
- The sizeof operator is normally used to determine the lengths of array and structures.
- It is also used to allocate memory space dynamically to variables during execution of a program.
Example:
m = sizeof(sum);
n = sizeof(long int);
k = sizeof(235L);
|
|