Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday, 4 July 2021

Interview Hack#36 Answer

What will be the output of the program?

  1. 2 -6 5
  2. 2 -6 1
  3. 2 2 1
  4. Compiler error
  5. None of these

Correct answer 3)2 2 1

Explanation:
The statement int p:3; allows selecting only the last bits of the number
So,
The binary value of 2: 00000010 (Select three two-bit) we get 010 which is 2 in decimal.
Similarly,
The binary value of 6: 00000110
The binary value of -6: 11111001+1=11111010 (Select last three-bit) we get 010 which is 2 in decimal
The binary value of 5: 00000101 (Select last two-bit) we get 01 which is 1 in decimal

0 comments:

Post a Comment