Operator In C Programming Language

Operators:- 

You can perform many types of operations on those  variables by storing the values ​​inside the variables. 
For example, by storing the values ​​within two integer variables, you can perform the operation of addition and get the sum of values ​​of both those variables printed. 
Similarly, you can perform with different operations variables. To perform operations with variables, you have to use different operators. In this chapter, you are being told about similar operators. The variables that are used with operators in operations are called operand.
Read Also:
  1. Data Structures
  2. Preprocessor Directives
  3. Linked List
C supports a rich set of built-in operators. We have already used several of them, such as =,+,-,* ,& and <. An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.

Operators are used in programs to manipulate data and variables. They usually form a part of the mathematical or logical expressions.

Type Of Operators:- 

C operators can be classified into several types:
  • Arithmetic operators 
  • Relational operators 
  • Logical operators 
  • Assignment operators
  • Increment and decrement operators 
  • Conditional operators 
  • Bitwise operators 
  • Special operators

1. Arithmetic operators:- 

An arithmetic operator is a symbol which performs arithmetic operation namely, addition, subtraction, multiply etc. The data on which such operations are carried out may be a variable or a constant. C supports the several arithmetic operators as given in the below table:

2. Relational operators:- 

Relational operators are used to compare values between two variables and form relational expressions, when Value becomes 1 condition is true and when value becomes 0 condition is false.
Read Also:
  1. Union
  2. Pointer
  3. File Handling
C supports six relational operators in all. These operators and their meanings are shown in the below table:
Relation operators

3. Logical Operators:- 

Logical operators are used with decision making statements. These operators are used to check two conditions together in control statements. The logical operators && and || are used when we want to more than one condition and make decisions.
For example: a> b && x==10 
An expression of this type, which combines two or more relational expression, is termed as a logical expression or a compound relational expression.

4. Assignment operators:- 

Assignment operators are used to assign the values ​​to each other of the variable. The assignment operator is represented by the equal sign (=). The variable appearing on the left side of =sign and it is assigned the value appearing on the right side of this sign. The assignment statement takes the following format: 
variable_name=expression; 
x-= y; is same as x=x-y;
x*= y; is same as x=x*y; 
x/= y; is same as x=x/y; 
x%= y; is same as x=x%y;

5. Increment and decrement operators:- 

These operators are use to increase or decrease the value of any variable from a number. The increment and decrement operators in C are represented by ++ and--sign respectively. The operator ++ means "add 1",and the operator--means "subtract 1". 

6. Conditional operators:- 

It is a pair of three operands is available in C to make conditional expresions of the form: 
exp1? exp2:exp3 
where exp1, exp2, and exp3 are expressions. If condition is true then exp1 will be return else exp2 will be return.

7. Bitwise operators:- 

Bitwise operators are special operators which 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.
AND operator performs AND operation with bits with the same position of both variables.
The OR operation with bits with the same position of both variables is performed by this operator.
NOT operator is used with only one operand. All bits of the value of the variable with it is used are opposite. For example, if it is 0 then it becomes 1 and if it is 1 it becomes zero. 
XOR is a special type OR operator. This operator returns 1 when the opposite bits occur and returns 0 when there are the same bits.
LEFT SHIFT operators are the bits of the operator left side variable. Shifts to the left as much as the value given in the variable on the right side.
RIGHT SHIFT operator are the bits of the operator left side variable. Shifts to the right as much as the value given in the right side variable.

Post a Comment

0 Comments