为什么在这种情况下会丢弃该值? [英] Why does the value get discarded in this case?
问题描述
当我有:
int main(无效)
{
int x = 256;
x>> 8;
printf("值为:%d \ n",x);
返回0 ;
}
我得到:
[cdalten @ localhost~] $ gcc -g -Wall seq .c -o seq
seq.c:在函数''main'':
seq.c:6:warning:语句无效
[cdalten @ localhost~] $ ./seq
值为:256
然而,当我将x从x>> 8更改为x ++时/>
#include< stdio.h>
int main(无效)
{
int x = 256;
x ++;
printf("值为:%d \ n",x);
返回0;
}
我得到:
[cdalten @ localhost~] $ gcc -g -Wall seq.c -o seq
[cdalten @ localhost~] $ ./seq
值为:257
>
问题是,为什么x>> 8丢弃了值得
走了,但x ++不是吗?
gcc -g -Wall seq.c -o seq
seq.c:在函数''main''中:
seq.c:6:warning:语句无效
[cdalten @ localhost~]
./ seq
值为:256
然而,当我改变时x从x>> 8到x ++
#include< stdio.h>
int main(无效)
{
int x = 256;
x ++;
printf("值为:%d \ n",x);
返回0;
}
我得到:
>
[cdalten @ localhost~]
gcc -g -Wall seq.c -o seq
[cdalten @ localhost~]
When I have:
int main(void)
{
int x = 256;
x>>8;
printf("The value is: %d\n", x);
return 0;
}
I get:
[cdalten@localhost ~]$ gcc -g -Wall seq.c -o seq
seq.c: In function ''main'':
seq.c:6: warning: statement with no effect
[cdalten@localhost ~]$ ./seq
The value is: 256
However, when I change x from x>>8 to x++
#include <stdio.h>
int main(void)
{
int x = 256;
x++;
printf("The value is: %d\n", x);
return 0;
}
I get:
[cdalten@localhost ~]$ gcc -g -Wall seq.c -o seq
[cdalten@localhost ~]$ ./seq
The value is: 257
The question is, how come something like x>>8 discards the value right
away, but x++ doesn''t?
gcc -g -Wall seq.c -o seq
seq.c: In function ''main'':
seq.c:6: warning: statement with no effect
[cdalten@localhost ~]
./seq
The value is: 256
However, when I change x from x>>8 to x++
#include <stdio.h>
int main(void)
{
int x = 256;
x++;
printf("The value is: %d\n", x);
return 0;
}
I get:
[cdalten@localhost ~]
gcc -g -Wall seq.c -o seq
[cdalten@localhost ~]
这篇关于为什么在这种情况下会丢弃该值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!