Bitwise Shifting Long inside Printf : C Interview Questions

February 20, 2025 No Comments » Hits : 50






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\n", 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

and so on…