c语言中左移问题
下面是在GCC上面的程序及结果
#include <stdio.h>
int main()
{
int b = 32;
printf("1<<b=%d\n",1<<b);
printf("1<<32=%d\n",1<<32);
return 0;
}
结果
[wang@Aming Desktop]$ gcc -o test test.c
test.c: In function ‘main’:
test.c:7: warning: left shift count >= width of type
[wang@Aming Desktop]$ ./test
1<<b=1
1<<32=0
个人分析:
首先编译部分的警告应该是这样理解的,其中一个是变量,一个是常数。编译知识检查语法及规则的方面的错误或者警告,所以,对于1<