c - C 中 main 中或 main 之前的函数原型(prototype)

标签 c

C中的函数原型(prototype)应该在main中还是在main之前。我在 main 之前被教过,但我 friend 的课本在 main 中显示了它。哪种方法正确?

他的书显示了这一点:

int main()
{
    void numberTable();

    numberTable();
}

void numberTable()
{
    int num;
    ...rest of the code...
}

最佳答案

两者都是正确的。
如果在 main 中添加函数声明,则其范围在 main { }.
如果将其添加到 main 之外,则其范围是整个源文件。

关于c - C 中 main 中或 main 之前的函数原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7656906/

相关文章:

c - 使用 sem_open 初始化信号量

c - 绘制回调内绘制和绘制回调外绘制

c - 在C中获取字符串的整个输入

c - 解析 mac 地址和移动 temp 时检查 strtol() 时出错。指针向上

c - while 和 eof 不起作用

c - 打开 Watcom Linker 在链接 C 和 Fortran 代码以构建 Matlab mex 文件时发现 undefined reference

c - 为什么 yacc 或 bison 将 $1 翻译为 yyvsp[(1) - (1)].s?

c - 在 C 中初始化二维字符数组

找不到素数

c - 在 main 外部定义的函数内分配 main 中的数组