Examveda
Examveda

What will be the output of the following code fragment?
void main()
{
   printf("%x",-1<<4);
}

A. fff0

B. fff1

C. fff2

D. fff3

E. fff4

Answer: Option A

Solution(By Examveda Team)

-1 will be represented in binary form as:
1111 1111 1111 1111

Now -1<<4 means 1 is Shifted towards left by 4 positions, hence it becomes:
1111 1111 1111 0000 in hexadecimal form - fff0.


This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 2 )

  1. Gayathri
    Gayathri :
    3 years ago

    Binary representation of 1 for 16 bits=0000 0000 0000 0001 then take 1's complement so, 1111 1111 1111 1110 then take 2's complement so 1111 1111 1111 1111 then take left shift

  2. Narendra B
    Narendra B :
    3 years ago

    -1 binary?

Related Questions on Operators and Expressions