Thursday, December 17, 2020

Operators in 'C':

 An operator specifies an operation to be performed that yields a value.

1.Arithmetic operators

2. Assignment operators .

3. Increment and Decrement operators

4. Relational  operators.

5. Logical operators

6. Conditional operator

7. Comma operator

8. Sizeof operator

9. Bitwise operators

      10. Other operators


1. Arithmetic operators:  It is used for numeric calculations.

They are of two types:

1. Unary Arithmetic Operators

2. Binary Arithmetic Operators

Unary Arithmetic Operators: Unary operators require only one operand. For e.g +x -y

Binary Arithmetic Operators: Binary operators require two operands.  There are five binary arithmetic operators.



Integer Arithmetic:  In which both operands are integer



Floating-Point Arithmetic:  In which both operands are integer type.



2. Assignment Operator :  A value can be stored in a variable with the use of assignment operator. 

The operator ‘=’ is used in assignment operator & statement.



Compound Assignment


3. Increment/ Decrement  Operators: These are the unary operators because they operate on a single operand. Increment(++) and decrement(--) used to increase and decrease the value by 1.


1. Prefix Increment/ Decrement:




2. Postfix Increment/ Decrement:





4. Relational Operators:

It is used to compare values of two expressions depending on their relationship.


Let us take two variables a=9 and b=5 . Evaluate the value.





5. Logical Operators:  An expression that combines  two or more expressions in terms of logical expression. The operator returns 0 for false and 1 for true.



1.AND(&&) Operator: This  gives true if both conditions are true, otherwise the result is false.





2. OR(||) Operators: This operator gives results false , if both conditions are false, otherwise the result is true.



3. Not(!) Operator: This is a unary operator and it negates the value of the condition . If the value of the condition is false  then it gives the value true.


6. Conditional Operator: Conditional operator is a ternary (? And :) which requires three expressions as operands.

Syntax:   TestExpression ? Expression1: Expression2

e.g.  a > b ? a : b

Suppose a=5 and b=8 then,

Max=a > b ? a : b 



7. Comma Operator: Expressions are separated using comma operator. The expressions are evaluated from left to right and the type and value of the compound expression.

e.g.   a=8, b=7, c=9, a+b+c

a=8, b=7, c=9


sum=a+b+c






Sizeof Operator: It is a unary operator . This operator gives the size of its operand in terms of bytes . The operand can be variable, constant or any data types( int, float, char etc)



Bitwise Operator: C has the ability to support the manipulation of data at the bit level. Bitwise operators are used for the operations on individual bits. It operates only on integers. 











No comments:

Post a Comment