Discussion
Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.
Answer: A
Correct answer: True
For unsigned types the arithmetic is defined to wrap modulo \( 2^n \), so a left shift by one is exactly a multiplication by two with any overflow discarded rather than undefined.
That is the whole difference from the signed case, where shifting a value whose significant bits reach the sign position is undefined behaviour. The char in the question is promoted to int before the shift, so the operation happens in a wider type; the guarantee is what makes shift-based multiplication safe on unsigned values and unsafe on signed ones.
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