Discussion
In the statement expression1 >> expression2. if expression1 is a signed integer with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer
Answer: A
Correct answer: True
Right-shifting a signed value with the sign bit set is implementation-defined in C: the standard permits either an arithmetic shift, propagating the sign bit so the value stays negative, or a logical shift, bringing in zeros so it becomes a large positive number.
In practice every common compiler chooses the arithmetic shift, but portable code cannot rely on it because the standard does not require it. The safe course is to cast to an unsigned type when the bit pattern is wanted, and to divide when the arithmetic result is wanted.
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