1.
int main() { char c = 'A'; printf("c=%c", c); }
int main() { char c = 65; printf("c=%c", c); }
这两个结果相同 都是c=A
但如果都以%d的格式输出
int main() { char c = 65; printf("c= %d", c); }
int main() { char c = 'A'; printf("c=%d", c); }
则结果为c= 65
但如果
int main() { char c; c = 200; printf("c=%d", c); }
首先 char其实默认是signed int,但-128<char<127,200的话换成二进制就是11001000,第一位符号数是1,取其补码后换算成十进制即为-56
则 c=-56
int main() { unsigned char c; c = 200; printf("c=%d", c); }
如果声明char为无符号数 则0<char<255
则c=200