CP I/O Q10

0. If the following program fragment ( assume negative numbers are stored in 2's complement form )
unsigned i=1;
int j = -4;
printf( " %u ", i + j);
prints x, then printf( " %d ", 8* sizeof( int ));
outputs an integer that is same as (log in the answers are to the base two)

  • Option : C
  • Explanation :
    Let size of ( int ) = 1. So, -4 will be stored as 1 1 1 1 1 1 0 0.
    Since we are adding unsigned and signed integers, the signed gets converted to unsigned.
    So, i + j will become 1 1 1 1 1 1 0 1. We are trying to print this as an unsigned integer.
    So, what is printed will be 28 - 1 - 2. So, log (x + 3) = 8 (i.e.. 8 * sizeof ( int)}.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *