gpt4 book ai didi

c - putc() 在 c 中返回什么?

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:44 25 4
gpt4 key购买 nike

我很想知道 putc() 返回什么。我正在浏览以下链接:https://www.tutorialspoint.com/c_standard_library/c_function_putc.htm .现在,如果 putc() 在出错时返回 EOF,那么一个自然的问题是它在文件末尾返回什么?为此,我在 dev c++ 中编写了以下内容:

代码

#include <stdio.h>

int main() {
char ch = EOF;
printf("%d\n", putc(ch, stdout));
printf("hello %d", EOF);

return 0;
}

输出

255
hello -1

这有点奇怪。谁能帮我吗 ? EOF 不是 What is the ascii value of EOF in c.? 中所述的 ASCII 字符那为什么第一行是 255(是的,它不是 ASCII),第二行是 -1

最佳答案

EOF 是 -1,您可能已经发现了。所以如果你putc(EOF,stdout)然后你看到255在输出中,因为 -1 被转换为 unsigned char打印前。

关于c - putc() 在 c 中返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45189507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com