void main() {union { int k; char i[2]; }*s,a; s=&a; s->i[0]=0x39;s->i[1]=0x38; printf("%d\n",s->k);void main(){union{int k;char i[2];}*s,a;s=&a;s->i[0]=0x39;s->i[1]=0x38;printf("%d\n",s->k);}求输出结果(详细解及思路)
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 18:04:08
void main() {union { int k; char i[2]; }*s,a; s=&a; s->i[0]=0x39;s->i[1]=0x38; printf("%d\n",s->k);void main(){union{int k;char i[2];}*s,a;s=&a;s->i[0]=0x39;s->i[1]=0x38;printf("%d\n",s->k);}求输出结果(详细解及思路)
void main() {union { int k; char i[2]; }*s,a; s=&a; s->i[0]=0x39;s->i[1]=0x38; printf("%d\n",s->k);
void main()
{union
{
int k;
char i[2];
}*s,a;
s=&a;
s->i[0]=0x39;s->i[1]=0x38;
printf("%d\n",s->k);
}
求输出结果(详细解及思路)
void main() {union { int k; char i[2]; }*s,a; s=&a; s->i[0]=0x39;s->i[1]=0x38; printf("%d\n",s->k);void main(){union{int k;char i[2];}*s,a;s=&a;s->i[0]=0x39;s->i[1]=0x38;printf("%d\n",s->k);}求输出结果(详细解及思路)
union {// 着是个共用体,就是说int的k与char*2的i[2]共用同一个存储空间
int k;
char i[2];
}*s,a;
s=&a;// s指向a的地址
s->i[0]=0x39;// 将16进制的39(2进制00110101)写入a.i[0];
s->i[1]=0x38;// 将16进制的38(2进制00110100)写入a.i[1];
printf("%d\n",s->k);// 输出a.k(2进制0011010100110100)并换行
对了,这里还要看int占几位,
若int占2位则结果是14393;(0x3839)
若int占4位结果就是-859031495;(0xcccc3839)