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;
}
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development