c - #include <stdio.h> 和 printf() 有什么关系?

标签 c c-preprocessor

#include <stdio.h>
main()

printf();

预处理器和函数之间有什么联系?

最佳答案

当 C 预处理器读取行 #include <stdio.h> 时, 它从字面上读取文件 stdio.h从系统目录并用内容替换此行。然后 stdio.h包含 printf 的声明和其他函数,告诉 C 编译器这些函数存在于另一个文件或库中

当您使用 printf() 时在你的代码中,编译器知道这个函数并且知道它不必担心它。 (但是,如果您不包含 stdio.h ,编译器根本不知道该函数是什么样的,这可能会很麻烦,并且编译器会对此进行提示。)

一个例子 stdio.h文件 printf可能看起来像这样:

/* stdio.h */

// Declaration of printf
int printf(const char *format, ...);

// And also a bunch of other function declarations...

关于c - #include <stdio.h> 和 printf() 有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23177385/

相关文章:

c - 为什么要使用 define 关键字来定义函数

c - 在获取 bashrc 时启动应用程序

c - 在步进电机的 C 结构中返回数组值

c - 调试 makefile

c - 使用 semaphore.h 和 ucontext.h 找不到这样的文件

c - __DARWIN_C_LEVEL C 预处理器符号是什么?

c-preprocessor - 如何解释 C 预处理器输出中的#前缀行?

c - ASCII、ISO 8859-1、Unicode 在 C 中如何工作?

c++ - 预处理器tomfoolery(字符串化#include)

c++ - 您可以在 C++ 中制作自定义运算符吗?