2007年9月18日星期二

char c=255?

char c=255;
int i=c;
what will be the value of i?

Unfortunately ,the answer is undefined.

It is implemention-defined whether a plain char is considerer signed or unsignded.

On a SGI Challenge machine,a char is unsigned,so the answer is 255. On a Sun SPARC or an IBM PC,where a char is signed,the answer is -1.

some standard library functions ,such as strcmp(), take plain chars only.

(C3.4 Signed and Unsigned Characters)

没有评论: