**Allocation and Storage part of C programming **
在尝试通过不同的数字系统打印负数时,我产生了一些疑问。在打印负数时,我得到不同的输出值。但我不清楚。如果有人帮助我,将不胜感激。
#include<stdio.h>
int main( )
{
char a = -5;
unsigned char b = -5;
int c = -5;
unsigned int d = -5;
//try to print as using "%d" format specifier to display decimal value
printf("%d %d",a,b);
printf("%d %d",c,d);
//try to print as using "%o" format specifier to display octal value
printf("%o %o",a,b);
printf("%o %o",c,d);
//try to print as using "%x" format specifier to display hexa-decimal value
printf("%x %x",a,b);
printf("%x %x",c,d);
return 0;
}
输出:-
displaying decimal value
a = -5 b = 251
c = -5 d = -5
displaying octal value
a = 37777777773 b = 373
c = 37777777773 d = 37777777773
displaying Hexa-decimal value
a = fffffffb b = fb
c = fffffffb d = fffffffb
现在,进入正题。我不知道为什么 unsigned char 只占用 8 位(1 字节)而其他分配给 32 位(4 字节)。