关于C中无符号类型的说明

问题描述 投票:4回答:3

嗨,我目前正在学习C,有些事情我还是不太了解。首先,我被告知如果我这样做:

unsigned int c2 = -1;
printf("c2 = %u\n", c2);

根据此表,它将输出255:

table

但是我得到一个奇怪的结果:c2 = 4294967295

现在奇怪的是,这有效:

unsigned char c2 = -1;
printf("c2 = %d\n", c2);

但是我不明白,因为char很好,所以char为什么什至打印出什么?由于此处的说明符是%d,而不是%u,对于无符号类型,应该是。

嗨,我目前正在学习C,有些事情我还是不太了解。首先,我被告知如果我这样做:unsigned int c2 = -1; printf(“ c2 =%u \ n”,c2);它将输出255,...

c memory char unsigned integer-promotion
3个回答
1
投票

在此声明中


1
投票

以下代码:


0
投票
在C整数中可以具有多个表示形式,因此多个存储大小和值范围有关更多详细信息,请参考下表。
© www.soinside.com 2019 - 2024. All rights reserved.