一个简单的C++程序求解释,越详细越好
#include<stdio.h>intmain(intargc,char*argv[]){unsignedshortinti=0;unsignedcharii=255;...
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned short int i = 0;
unsigned char ii = 255;
int j = 8, p, q;
p = j << 1;
q = j >> 1;
i = i - 1;
ii = ii + 1;
printf("i = %d\n", i);
printf("ii = %d\n", ii);
printf("p = %d\n", p);
printf("q = %d\n", q);
return 0;
}
结果
i = 65535
ii = 0
p = 16
q = 4 展开
int main(int argc, char *argv[])
{
unsigned short int i = 0;
unsigned char ii = 255;
int j = 8, p, q;
p = j << 1;
q = j >> 1;
i = i - 1;
ii = ii + 1;
printf("i = %d\n", i);
printf("ii = %d\n", ii);
printf("p = %d\n", p);
printf("q = %d\n", q);
return 0;
}
结果
i = 65535
ii = 0
p = 16
q = 4 展开
1个回答
展开全部
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned short int i = 0; //定义为无符号小整数,这样可以让相同的内存多存2倍大的数
unsigned char ii = 255;
int j = 8, p, q;
p = j << 1; //x << i表示 x*(2^i)
q = j >> 1; //x >> i表示 x/(2^i)
i = i - 1; //因为 i是无符号整数,所以减一后是无法表示负号的,所以会等于short int 能保存的最大值
ii = ii + 1; //因为char 最大能保存的就是 255的2进制数,所以加一后就爆了,等于0
printf("i = %d\n", i);
printf("ii = %d\n", ii);
printf("p = %d\n", p);
printf("q = %d\n", q);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询