Operators In C
{tocify} $title={Table of Contents}
Definition
An Operator is a symbol, which specifies what action to be taken upon Operands. An expression is basically a combination of operands & operators that yields a single value in which operand may be a variable or constant
Example Syntax
op1+op2
Here + is the operator and op1 and op2 are the operands
Types of operators
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Conditional Operators
- Special Operators
- Increment/Decrement Operators
Arithmetic Operators
Arithmetic operators perform arithmetic operations such as Addition, Subtraction, Multiplication, Division & Mod. Following table shows list of arithmetic operators :
Operator Description + Addition - Substraction * Multiplication / Division % Modulus All operators except %(Modulus); can be operated on int, float & char data types, whereas % (modulus) operator can be operated on int type only.
-
Relational Operators
Relational operators are used to compare 1st operand with 2nd operand to test whether 1st operand is greater than/ less than or equals to 2nd operand & so on. These operators are used to form conditions, also called relational expressions and these expressions are always evaluated to either TRUE (1) or FALSE (0). Following table shows list of relational operators :
Operator Description < Less than > Greater than <= Less than or equals to >= Greater than or equals to == Equals to != Not equals to -
Logical Operators
Logical operators are also called compound relational operators , used to combine two or more conditions (relational expressions) and always evaluated to either TRUE (1) or FALSE (0). Following table shows list of Logical operators :
Operator Description && Logical AND || Logical OR ! Logical NOT -
Bitwise Operators
Bitwise operators perform operations on integers at bit level. Following table shows list of Bitwise Operators :
Operator Description & Bitwise AND | Bitwise OR ^ Bitwise EX-OR << Bitwise Left-shift >> Bitwise Right-shift ~ Bitwise NOT or Compliment These operators are not applicable to float & double type.
-
Logical Operators
Logical operators are also called compound relational operators , used to combine two or more conditions (relational expressions) and always evaluated to either TRUE (1) or FALSE (0). Following table shows list of Logical operators :
Operator Description && Logical AND || Logical OR ! Logical NOT -
Assignment Operator
Assignment operator is used to assign a constant value or a variable or result of an expression to a variable.
Operator Description = Assignment operator -
Conditional Operator
Conditional operator(?:) also know as Ternary operator because it operates upon three operands.
Operator Description ?: Conditional Operator -
Special Operator
The (sizeof) operator returns the size of exp or datatype in bytes.Following tables shows some examples of special operators:
Syntax Result sizeof(int); returns 2 sizeof(float); returns 4 sizeof(char); returns 1 sizeof(long int); returns 4
Increment/Decrement operators
The increment and decrement operators are also called as unary operators because they always operates on single operand.
Increment(++) operators
Increment (++) operator always add one to the operand
operator | description |
---|---|
++operand | Pre Increment |
operand++ | Post Increment |
Decrement(--) operators
Decrement (--) operator always add one to the operand
operator | description |
---|---|
--operand | Pre Deccrement |
operand-- | Post Decrement |
There is no difference between Pre/Post form of Increment/Decrement when used as individuals. But when used in expressions , the Post( Post means after) form of Increment/Decrement the value of Operand is updated after assigning the original value to the expression and in case of pre (pre means before) form of Increment/Decrement the value of operand is updated before assigning the original value to the expression.
We Love Hearing from You!
Thank you for reading our post! Your thoughts and opinions are important to us. Please leave a comment below to share your feedback, ask questions, or start a discussion. We look forward to engaging with you!
Note: Comments are moderated to ensure a respectful and positive environment.