959 views
0 votes
0 votes
If the following 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 options are of  base 2)

a)8*log(x+3)     b)log(x+3)     c)unpredictable value    d)none of the above

2 Answers

0 votes
0 votes
Option (d) None of the above.

The correct expression would be log(x + 2) (Not present in the options).

The first printf would produce (UINT_MAX – 2) == (4294967293) == ((2**32 – 1) – 2). The second printf basically prints the number of bits in an int. We can take x, add 2, (which would set all the bits), and then take a log2 to get the number of bits present in an int.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
4
altamash asked Apr 12, 2019
322 views
int main();{int a,*b, c, *d, e;a=10;b=&a;c=&b;d=&c;e=&d;print f(“a=%d b=%u c=%u d=%u e=%u e=%u\n”, a,b,c,d,e);print f(“ %d %d %d \n”,a,a+*b, c+ *d+, e);return 0...