Machine-translated by Google. Questions are authored in English.
Top

Discussion

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include <stdio.h>

int main()
{
    unsigned int m = 32;
    printf("%x\n", ~m);
    return 0;
}

 

  • A.ffff
  • B.0000
  • C.ffdf
  • D.ddfd

Answer: C

Correct answer: ffdf

Write 32 in the given width first:

\[ 32 = 0000\,0000\,0010\,0000_2 = \mathtt{0x0020} \]

~ inverts every bit:

\[ 1111\,1111\,1101\,1111_2 = \mathtt{0xffdf} \]

The quick check is that inverting a hex digit means subtracting it from f: 0 becomes f, 0 becomes f, 2 becomes d, 0 becomes f. The distractor ffff would be ~0, and the width matters - on a 4-byte int the answer would be ffffffdf.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.