gpt4 book ai didi

在 ANSI C 中正确声明 main() 函数

转载 作者:太空狗 更新时间:2023-10-29 16:51:58 27 4
gpt4 key购买 nike

<分区>

C 标准说:

The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

int main(int argc, char *argv[]) { /*
... */ }

or equivalent or in some other implementation-defined manner.

然而,Kernighan & Ritchie 在他们的第二版(规范的 ANSI C)圣经中只使用:

main()
{
/* taram pampam ... */

return 0;
}

谁是对的?它是否与没有返回值的函数有关,自动假设在 C 中返回 int

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