Bit Pattern of the data can be shifted by specified number of Positions to Left
When Data is Shifted Left , trailing zero’s are filled with zero.
Left shift Operator is Binary Operator [Bi - two]
Binary means , Operator that require two arguments
Quick Overview of Left Shift Operator
Original Number A
0000 0000 0011 1100
Left Shift
0000 0000 1111 0000
Trailing Zero’s
Replaced by 0 (Shown in RED)
Direction of Movement of Data
<<<<<=======Left
Syntax : Bitwise Left Shift Operator
[variable]<<[number of places]
Live Example : Bitwise Operator [Left Shift Operator]
#include<stdio.h>intmain(){int a =60;printf("\nNumber is Shifted By 1 Bit : %d",a <<1);printf("\nNumber is Shifted By 2 Bits : %d",a <<2);printf("\nNumber is Shifted By 3 Bits : %d",a <<3);return(0);}
Output :
Number is Shifted By 1 Bit :120
Number is Shifted By 2 Bits :240
Number is Shifted By 3 Bits :480
Explanation of Left Shift Binary Operator :
We know the binary representation of the 60 is as below -
0000000000111100
Now after shifting all the bits to left towards MSB we will get following bit pattern -
In the previous topic we have studied Precedence of Value at and Address Operator of Pointer. In this chapter we will be looking more advance form of pointer. We are looking one step forward to learn how (++*ptr) works ?
Meaning of (++*ptr) in C Programming :
Consider the Following Example :
int num =20,*ptr ;
ptr =#printf("%d",++*ptr);
Explanation :
‘++’ and ‘*’ both have Equal Precedence
Associativity is from Right to Left ( Expression evaluated from R->L)
In the previous chapter, we have learnt about the memory organization of the pointer variable. In this chapter we are learning to compute or find the size of pointer variable.
What is the size of Pointer variable in C ?
Pointer is the variable that stores the address of another variable.
How to calculate size of Pointer ?
Consider the following memory map before declaring the variable.In the memory comprise of blocks of 1 byte.
Whenever we declare any variable then random block of memory is chosen and value will be stored at that memory location.
Similarly whenever we declare any pointer variable then random block of memory will be used as pointer variable which can hold the address of another variable.
Calculating Size of Pointer : Tips
Pointer stores the address of the Variable.
Size of Pointer Variable can be evaluated by using sizeof operator
Address of variable is considered as integer value.
Similarly if we declare the character array then it can hold only character. So in short character array can store character variables while floating array stores only floating numbers.
B. Array Used for Maintaining multiple variable names using single name
Suppose we need to store 5 roll numbers of students then without declaration of array we need to declare following -
int roll1,roll2,roll3,roll4,roll5;
Now in order to get roll number of first student we need to access roll1.
Guess if we need to store roll numbers of 100 students then what will be the procedure.
Maintaining all the variables and remembering all these things is very difficult.
Consider the Array :
int roll[5];
So we are using array which can store multiple values and we have to remember just single variable name.
C. Array Can be Used for Sorting Elements
We can store elements to be sorted in an array and then by using different sorting technique we can sort the elements.
Different Sorting Techniques are :
Bubble Sort
Insertion Sort
Selection Sort
Bucket Sort
D. Array Can Perform Matrix Operation
Matrix operations can be performed using the array.We can use 2-D array to store the matrix.
Matrix can be multi-dimensional
E. Array Can be Used in CPU Scheduling
CPU Scheduling is generally managed by Queue. Queue can be managed and implemented using the array. Array may be allocated dynamically i.e at run time. [Animation will Explain more about Round Robin Scheduling Algorithm | Video Animation]
F. Array Can be Used in Recursive Function
When the function calls another function or the same function again then the current values are stores onto the stack and those values will be retrieve when control comes back. This is similar operation like stack.
if-else-if Statement OR else if Ladder : Tutorial on If
if-else-if Statement OR else if Ladder :
Suppose we need to specify multiple conditions then we need to use multiple if statements like this -
voidmain(){int num =10;if( num >0)printf("\n Number is Positive");if( num <0)printf("\n Number is Negative");if( num ==0)printf("\n Number is Zero");}
which is not a right or feasible way to write program. Instead of this above syntax we use if-else-if statement.
Consider the Following Program -
voidmain(){int num =10;if( num >0)printf("\n Number is Positive");elseif( num <0)printf("\n Number is Negative");elseprintf("\n Number is Zero");}
Explanation :
In the above program firstly condition is tested i.e number is checked with zero. If it is greater than zero then only first if statement will be executed and after the execution of if statement control will be outside the complete if-else statement.
elseif( num <0)printf("\n Number is Negative");
Suppose in first if condition is false then the second condition will be tested i.e if number is not positive then and then only it is tested for the negative.
elseprintf("\n Number is Zero");
and if number is neither positive nor negative then it will be considered as zero.