按位或不工作C.

Pro*_*mer -8 c

请帮我这个代码.我不知道为什么输出不是8.

#include <stdio.h>
#include <stdlib.h>
int main(){
    char c;
    c = c & 0;
    printf("The value of c is %d", (int)c);
    int j = 255;
    c = (c | j);
    int i =0;
    while( (c & 1) == 1){
        i++;
        c = c>>1;
    }
    printf("the value of i is %d",i);
    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

对于给我-1的所有人,我尝试打印这些值.但它进入了一个无限循环.

Oli*_*rth 8

您之前的问题中了解到,char已在您的平台上签名.因此,在while循环开始时,c具有负值.

右移负值是实现定义的.在您的平台上,我想它正在进行算术转换.