Are the shift operators (<<, >>) arithmetic or logical in C?

后端 未结 11 1421
粉色の甜心
粉色の甜心 2020-11-22 07:52

In C, are the shift operators (<<, >>) arithmetic or logical?

11条回答
  •  情话喂你
    2020-11-22 08:50

    According to K&R 2nd edition the results are implementation-dependent for right shifts of signed values.

    Wikipedia says that C/C++ 'usually' implements an arithmetic shift on signed values.

    Basically you need to either test your compiler or not rely on it. My VS2008 help for the current MS C++ compiler says that their compiler does an arithmetic shift.

提交回复
热议问题