Professional Documents
Culture Documents
03 Operators in C
03 Operators in C
03 Operators in C
EXPRESSION.
Expression is a statement which is form by the combination of functions, Operators and operands (i.e.
constants and variables).
The Variables and Constant itself are expression.
The expression that only involves constant are called as Constant Expression.
The types of expressions are Arithmetical, Relational etc.
Consider the expression A + B * 5. where,
o Operators are : +, *
o Operands are : Either Variables A, B and Constant is 5
o A + B * 5 is an expression.
OPERANDS
Operands are either variables or constants on which operator perform its operations.
OPERATORS.
“Operators are the meaningful symbols which are used to perform meaningful logical and
mathematical operations”.
Operator performs its operations on operands ( constants and variables ) in an expression.
TYPES OF OPERATORS.
1. Arithmetical Operators
2. Assignment Operator.
3. Compound Assignment Operators.
4. Relational Operators.
5. Logical Operators.
6. Conditional Operator.
7. Increment or decrement Operator.
8. Bit Wise Operators.
9. Special Operators
o For Example :
1. A += 10 ; // It increase the existing value of A by 10.
RELATIONAL OPERATOR
o These operators are used to compare the relation between two operands.
o It returns the result true(non zero value) or false (zero value).
o The list of relational operator is as follow.
Note :
10 > 20 returns the result 0 because condition is false.
10 < 20 returns the result 1 because condition is true.
These operators are used to build the condition.
it is used with decision making statement.
It execute different block of statement depending on the result of condition.
LOGICAL OPERATOR
o These operators are used to perform logical operations.
o These operators are used to compare more than one condition at a time.
o These operators returns true (Non Zero ) or false ( 0 ) , after finding the result of all given
conditions.
o There are three types of logical operators.
CONDITIONAL OPERATOR
o This operator is also called as ternary operator.
o It is denoted by the “?:” Sign.
o Conditional operators return one value (followed by ? ) if condition is true and returns other value (
followed by : ) if condition is false.
o It takes three arguments.
o Syntax : Expression1 ? Expression2 : Expression3;
o Here Expression1 is evaluated first,
o If it is true, then Expression2 is evaluated and its value becomes the value of the expression.
o If it is false, then Expression3 is evaluated and its value becomes the value of the expression.
o For Example :
o Int C = A > B ? A : B;
o In above example, if A is greater than B, it returns value of A in variable C otherwise it returns value
of B in variable C.
o There are 6 bit wise operators, and they are explain below
Bitwise OR – |
It takes 2 bit patterns and
It performs OR operations on each pair of corresponding bits.
The following example will explain it.
Int x = 20 | 25; // Store 29 in x
Bitwise AND – &
It takes 2 bit patterns, and perform AND operations with it.
The Bitwise AND will take pair of bits from each position,
COMMA OPERATOR
o It is denoted by the “,” Sign.
o We can combine/link two related expression into one.
o It returns the value of right most operand.
o It has the lowest precedence than other operators.
o Comma operator can act as
1. As Operator : When it is used in Expression.
2. As Separator : When it is used in Declaring variable, Function call and definition for
parameter separation.
o For Example :
1. Int a=1, b=2; // As Operator
2. X = ( A , B) // As Separator
SPECIAL OPERATORS
o SizeOf Operator :
1. This is compile time operator and used with operand. It returns the number of bytes the
operands occupies in memory.