c - 函数内部的函数声明——为什么?

标签 c function

我正在阅读“C 语言编程”这本书,并在第 10 章中找到了这样一个示例:

#include <stdio.h>

void test (int  *int_pointer)
{
     *int_pointer = 100;
}

int main (void)
{
     void test (int  *int_pointer);
     int  i = 50, *p = &i;

     printf ("Before the call to test i = %i\n", i);

     test (p);
     printf ("After the call to test i = %i\n", i);

     return 0;
}

我理解这个例子,但我不理解 main 中的 void test (int *int_pointer); 行。为什么我要重新定义test的签名呢?这是惯用的 C 语言吗?

最佳答案

它绝对不是惯用的 C,尽管它是完全有效的(多个声明是可以的,多个定义不是)。这是不必要的,因此没有它代码仍然可以完美运行。

如果有的话,也许作者是故意的

void test (int *int_pointer);

int main (void) {

    ...

}

如果函数定义放在 main () 之后。

关于c - 函数内部的函数声明——为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29746768/

相关文章:

python - 如何在python中超时功能,超时不到一秒

python - 发送到 Citrix 应用程序时在 Python 脚本中模拟硬件按键(SendKeys 不起作用)

c - 理解 scanf 语法

c - C语言如何拦截或包装传递给API接口(interface)的函数指针

c++ - C++ 中的 void(*) 有什么意义吗?

r - dplyr: "Error in n(): function should not be called directly"

c - 释放内存的正确方法

c - 如何通过鼠标单击获取像素的 RGB 颜色值

javascript - 使用 javascript 函数参数显示 jquery 选项卡

javascript - Javascript函数调用在IE和Chrome中不起作用