Sign extension with bitwise shift operation

前端 未结 5 1273
小蘑菇
小蘑菇 2021-01-06 02:23

following this Q&A I tried to exam the answer so I wrote:

#include 

int main ()
{

        int t;int i;
        for (i=120;i<140;i++){         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 03:17

    The rule in C and C++ is that the result of a right-shift of a negative value is implementation defined. So read your compiler's documentation. The various explanations you've gotten are valid approaches, but none of these is mandated by the language definition.

提交回复
热议问题