Ticker

6/recent/ticker-posts

Operators

Operators - 

There are various types of operators in C language including all the basic functions.
These are used to manipulate data and variables.
C operators can be classified into following types:
  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators
  • Assignment operators
  • Conditional operators
  • Special operators

Arithmetic operators - 

C supports all arithmetic operators. 


Image result for Arithmetic operators

Relational operators - 

These are used to compare various variables and inputs. These are used for checking equality or which is greater or lesser etc.



Logical operators -


These are 3 in number. 
  1. && - Logical And [Both must satisfy the condition]
  2. || - Logical Or [Any one or both must satisfy]
  3. ! - Logical Not [changes the result]
Whenever the input value is 0 ; it will print 0(false); and for the rest prints 1(true)
Let us take an example -
Let a=10 , b=0;
  1. a&&b = 0 (false) [As b=0]
  2. a||b=1 (true)  [As a=1]
  3. !a=0 (false) [As a is 1[true]; not will change its value to 0(false)]


Assignment operators - 

These are used to assign values. And follows as shown below - 


Image result for assignment operators


Conditional operators - 

This is a substitute of if else statement using basic operators( ? : ).
It is also known as Ternary Operators.

The syntax of a conditional operator is :
expression 1 ? expression 2: expression 3
Explanation:
  • The question mark "?" in the syntax represents the if part.
  • The first expression (expression 1) generally returns either true or false, based on which it is decided whether (expression 2) will be executed or (expression 3)
  • If (expression 1) returns true then the expression on the left side of " : " i.e (expression 2) is executed.
  • If (expression 1) returns false then the expression on the right side of " : " i.e (expression 3) is executed.


Special Operators - 

  1. & - defines the address to the input.
  2. sizeof - Tells the size of the value inserted.
  3. * - Adds a pointer to the variable. 


Bitwise Operators -

These are the operators that act on the bits. These do not work on float or double data types. 
  1. Bitwise And 
  2. Bitwise Or 
  3. Bitwise Xor 
  4. Left shift 
  5. Right shift 
Now lets see truth table for bitwise &| and ^
aba & ba | ba ^ b
00000
01011
10011
11110
The bitwise shift operator, shifts the bit value. The left operand specifies the value to be shifted and right one tells the no of spaces.

Post a Comment

0 Comments