gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:15:40 27 4
gpt4 key购买 nike

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/

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