Exercise 1-7. Write a program to print the value of EOF.
比 Exercise1_6 还简单。用 printf() 输出即可,记得用整数 %d 。
完整代码如下:
#include <stdio.h>
int main(void) {
printf("The value of EOF is %d.\n", EOF);
return 0;
}
运行后可以看到 EOF 的值是 -1 :
> ./Exercise1_7
The value of EOF is -1.
其实 EOF 是被包含在头文件 stdio.h 里面的。可以参考 GNU 的 stdio.h 源文件:
第90行:
00090 #define EOF (-1)
由此可见 EOF 是一个宏,简单可以理解成它就是-1。