Main(){ int i = 0xff ; printf("n%d", i

A) 1020
B) 512
C) 4
D) 1024

Showing Answers 1 - 8 of 8 Answers

Amit

  • Dec 14th, 2005
 

output is 1020since oXff is in hexadecimal form .decimal equivalent of it is 255.so 255<<2 is equivalent multiplication by 4 ie.1020

  Was this answer useful?  Yes

C_learner

  • Jan 18th, 2006
 

f=15 in hex equivalent...so the number is (15*16power0)+ (15*16power1) = 255....and <<2 would multiply it by 4 (2 power 2)...

So the answer is 255*4 = 1020...

  Was this answer useful?  Yes

Here decimal eqivalent of OXFF is 255. Assuming integer is 16 bit, binary representation of OXFF will be: 0000000011111111

Next come to the i<<2, this left shift operator will shift the 2 bits left of binary eqvlnt of 255.
Aefter shifting 2 bits left of binary representation of 255 will be: 0000001111111100 whose decimal eqvlnt is 1020.

It can be calculated in other way also. In case of left shift operation the result should be: (number)*(2^(no of bits to be shifted)).
Here number is :255
No. of bits to be shifted is:2(as i<<2)
So ans is: 255*(2^2)=1020

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions