该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*程序注解:位域的定义和使用,以及位操作符的运算*/
#include "stdio.h"
/*该数据结构供占用6个字节即6*8=48位*/
struct data
{
unsigned a:8;
unsigned b:1;
unsigned :0;
unsigned c:7;
unsigned d:2;
unsigned :2;
unsigned e:4;
unsigned f:3;
unsigned g:5;
unsigned h:6;
}bit,*pbit;
main()
{
bit.a=255;
bit.b=1;
bit.c=127;
bit.d=3;
bit.e=15;
bit.f=7;
bit.g=31;
bit.h=63;
printf("Use structure name output--->>>\n");
printf("a=%d\n",bit.a);
printf("\nb=%d\n",bit.b);
printf("c=%d\n",bit.c);
printf("\nd=%d\n",bit.d);
printf("e=%d\n",bit.e);
printf("\nf=%d\n",bit.f);
printf("g=%d\n",bit.g);
printf("\nh=%d\n",bit.h);
printf("Use pointer output--->>>\n");
pbit=&bit;
pbit->a+=1;
pbit->b=~pbit->b;
pbit->c&=3;
pbit->d|=0;
pbit->e^=10;
pbit->f<<=2;
pbit->g>>=2;
pbit->h+=2;
printf("a=%d\n",pbit->a);
printf("b=%d\n",pbit->b);
printf("c=%d\n",pbit->c);
printf("d=%d\n",pbit->d);
printf("e=%d\n",pbit->e);
printf("f=%d\n",pbit->f);
printf("g=%d\n",pbit->g);
printf("h=%d\n",pbit->h);
getch();
}
/* 输出结果如下:
Use structure name output--->>>
a=255
b=1
c=127
d=3
e=15
f=7
g=31
h=63
Use pointer output--->>>
a=0
b=0
c=3
d=3
e=5
f=4
g=7
h=1
*/