用C什么是EOF的价值和'\\ 0' [英] What is value of EOF and '\0' in C

查看:121
本文介绍了用C什么是EOF的价值和'\\ 0'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 EOF '\\ 0'的类型是整数,但如果这样不应该,他们有一个固定的值?

I know that EOF and '\0' are of type integers, but if so shouldn't they have a fixed value?

我都印制,并得到-1 EOF 0为'\\ 0'。但这些数值固定的吗?

I printed both and got -1 for EOF and 0 for '\0'. But are these values fixed?

我也有过这样

int a=-1;

printf("%d",a==EOF); //printed 1

EOF值'\\ 0'固定的整数?

推荐答案

EOF 是扩展到使用类型整型常量前pression宏 INT 和实施相关的负值,但很常用-1。

EOF is a macro which expands to an integer constant expression with type int and an implementation dependent negative value but is very commonly -1.

'\\ 0'字符在C值0 ++和 INT 在C值0。

'\0' is a char with value 0 in C++ and an int with the value 0 in C.

为什么的printf(%d个,一== EOF)的原因; 导致 1 是因为你没有指定值 EOF A 。相反,你检查是否 A 等于 EOF 既然这是真的( A == -1 == EOF )它印 1

The reason why printf("%d",a==EOF); resulted in 1 was because you didn't assign the value EOF to a. Instead you checked if a was equal to EOF and since that was true (a == -1 == EOF) it printed 1.

这篇关于用C什么是EOF的价值和'\\ 0'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆