目录
- 移位操作
- 位域
<一> 移位操作
注意事项:
&&、||和!分别是与或非的逻辑运算符
&、|和~分别是与或非的位运算符
<二> 位域
作用:在结构体中,通过指定某个成员的位数来对成员实现某种限制并减少结构体的大小;
#include <stdio.h>
struct{
unsigned int yes;
unsigned int no;
}test1;
struct{
unsigned int yes:1;
unsigned int no:1;
}test2;
int main(){
printf("%d,%d\n",sizeof(test1),sizeof(test2));
test1.yes = 6;
test2.yes = 1;
printf("%d,%d\n",test1.yes,test2.yes);
return 0;
}
//8,4
//6,1
程序分析:
如果test2.yes = 6,