Operator in C Programming Language
Operators is one of the TOKEN which is use to perform specific operations on different values/operands. Like arithmetic, relational, assignment etc...
C Program support eight (8) operators:
- Arithmetic Operator
- Assignment Operator
- Relational Operator
- Conditional Operator
- Increment and Decrement Operator
- Logical Operator
- Bitwise Operator
- Special Symbol Operator
1. Arithmetic Operator:
- Arithmetic operators are used to perform arithmetic operations like... +, -, *, /, % .
- Real Arithmetic:
- when we perform arithmetic operations on real numbers, answer will be in real number.
- Example:
- Mix Mode Arithmetic:
- When we perform arithmetic operations on those numbers in which some numbers are integer and some are real then answer will be floating number.
- Example:
2. Relational Operators:
- When we want to compare two operands or values, we use relational operators.
- Relational operator represent relation between two operands.
- There are six relational operators.
- Relational operators are used in conditional statement like if-else and looping statements like for, while or do while.
3. Assignment Operators:
- When we want to assign any value operand or expression to any variable then we can use assignment operators(=).
- Syntax:
- variable_name OP value/operand/expression
- Example:
- Short Hand Assignment Operator:
- a=a+1 --> a+=1
- a=a*1 --> a*=1
- a=a-b --> a-=b
- a=a/5 --> a/=5
- x=x*(n+1) --> x*=(n+1)
- x=x+(n*m-o) --> x+=(n*m-o)
- When same operand is use at left hand side and right hand side of assignment operator in any equation, then short hand assignment operator can be used.
- Syntax:
- Variable_name OP = expression.
4.Logical Operators:
- Logical operator is used to check multiple conditions and make decision.
- There are three logical operators:
- Logical AND (&&)
- Logical OR (||)
- Logical NOT (!)
- LOGICAL AND:
- Logical AND operator check all conditions if all conditions are throw then only true block will be executed.
- If only any one condition is false then false block will be executed and it will return (0).
LOGICAL AND TABLE
- LOGICAL OR:
- Logical OR operator check all condition if any one condition is true then it will return 1.
LOGICAL OR TABLE
- LOGICAL NOT:
- Logical NOT operator give reverse result of given condition.
- If condition is false then it will return 1 (true).
- If condition is true then then it will return 0 (false).
5. Conditional Operator: (? :)
- Ternary operator ? and : are used to give condition in following expression.
- exp1 (condition) ? exp2(if condition is true) : exp3(else false)
- In this expression, exp1 is true then exp2 will be assigned to variable.
- If exp1 is false then exp3 will be assigned to variable.
6. Increment Decrement Operator:
- Increment Decrement operator are used to increment or decrement a value by 1.
- This operator is use in looping statement.
- There are two increment operators:
- Post Increment Operator : a++
- Pre Increment Operator : ++a
- There are also two decrement operators:
- Post Decrement Operator : a--
- Pre Decrement Operator : --a
7.Bitwise Operator:
- Bitwise operator are use to perform operations on bits.
- Mainly there are 5 bitwise operators:
- & bitwise AND
- | bitwise OR
- ^ bitwise XOR
- << shift left
- >> shift right
- & bitwise AND:
- If both bits are 1 there only answer will be 1 otherwise answer will be 0.
- & bitwise AND Table

- | bitwise OR:
- If value of any 1 bit is 1 then if value of answer will be 1, otherwise will be 0.
- | bitwise OR Table
- ^ bitwise XOR:
- If both bits are opposite then only answer will be 1 otherwise answer will be 0.
- ^ bitwise XOR Table
- << shift left:
- Shift left operation use to move number of bits position from left hand side.
- >> shift right:
- Shift right operation is use to move number of bits position from right hand side.
8. Special Operators:
- There are different special operator are as follows:
- , (comma) operators
- Size of operators
- Pointer operators (*,&)
- Pointer member operators (->) etc.
Comments
Post a Comment