第2个回答 2009-12-17
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char c1 = getchar();//这行定义成int c1 = getchar();运行效果一样
printf("char : %c\n",c1);
printf("int : %d\n",c1);
system("pause");
return 0;
}
输出是
char:a
int:97
97是a的ASCII值
另外c里还有强制转换,英文叫cast
类似这样
int n = 97;
char a = (char)n;
有的编译器会要求这个cast,要视具体情况灵活运用
--------------------------------------
楼上 250947644 说的
会减慢程序的运行速度
我倒是没想到,学习了本回答被提问者采纳