C bitwise shifting inside printf

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Bitwise Shifting Long inside Printf :

  1. L stands for Long.
  2. 1L means “1” is represented in the Long and then we are using Bitwise Shifting of the operators.

Guess the output of the following code ?

main()
{
int i;
for(i=0;i<5;i++)
   printf("%d
", 1L << i);
}

Output :

1
2
4
8
16

Explanation :

During First Loop

1L << 0
---------------------------------------
0000 0000 0000 0000 0000 0000 0000 0001

During 2nd Loop

1L << 1
---------------------------------------
0000 0000 0000 0000 0000 0000 0000 0010

10 in Decimal = 2

During 3rd Loop

1L << 2
---------------------------------------
0000 0000 0000 0000 0000 0000 0000 0100

100 in Decimal = 4