本文介绍了的getchar()不一致之处变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我读K&安培; R的书,我对本code的一个问题:

So I'm reading K&R book and I have a question regarding this code:

int c;
c = getchar();

为什么他们使用整型变量?那不是的getchar()返回字符的价值?所以,一个char会更适合?请赐教。

Why do they use integer variable? Isn't the value that getchar() returns a character? So a char would be more suitable? Please enlighten me.

推荐答案

的getchar()需要能够指示当它到达了输入的结尾它通过返回做到这一点 EOF ,这是故意超出了有效字符范围,它可以 ŧ冲突与人物出现在输入端。

getchar() needs to be able to indicate when it's reached the end of the input. It does this by returning EOF, which is deliberately outside the valid char range so it can't clash with a character appearing on the input.

这篇关于的getchar()不一致之处变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 22:24