Lesson 5

 

                                                Operators and Expressions


    Arithmetic Operators

Relational Operators

Logical Operators

Bitwise Operators

Assignment Operators

Miscellaneous Operators

Operator Precedence and Associativity

                    Type Conversions in Expression



 Arithmetic Operators


The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.


Relational Operators


In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. ... In languages such as C, relational operators return the integers 0 or 1, where 0 stands for false and any non-zero value stands for true

 

Logical Operators

 

 

Operator Description Example

&& Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false.

|| Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true.

! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A && B) is true.

 


Bitwise Operators


The bitwise operators are the operators used to perform the operations on the data at the bit-level.


Operator Meaning of operator

& Bitwise AND operator

| Bitwise OR operator

^ Bitwise exclusive OR operator

~ One's complement operator (unary operator)

<< Left shift operator

>> Right shift operator


Assignment Operators

 

All assignment operators have the same precedence and have right-to-left associativity.


Operator Description

<<= Left shift AND assignment operator.

>>= Right shift AND assignment operator.

&= Bitwise AND assignment operator.

^= Bitwise exclusive OR and assignment operator.



Miscellaneous Operators


Miscellaneous operators consist of three operands, the various operators are as follows.

Operator (?:) -> Conditional Expression (also an alternative for if-else condition). ...

Operator (sizeof()) -> Returns the size of a variable. ...

Operator (&) -> Returns the address of a variable. ...

Operator (*) -> Pointer to a variable.


operator Precedence and Associativity


Operator precedence: It dictates the order of evaluation of operators in an expression. Associativity: It defines the order in which operators of the same precedence are evaluated in an expression. ... In C, each operator has a fixed priority or precedence in relation to other operators.


 Type Conversions in Expression


  The type conversion process in C is basically converting one type of data type to other to perform some operation. The conversion is done only between those datatypes wherein the conversion is possible ex – char to int and vice versa.



Implicit Type Cast.

Explicit Type Cast.



Popular posts from this blog

LESSON 1