c语言函数原型说明,必须在C中声明函数原型吗?

5b5a04b81f0f041f9ff34eaa72712873.png

梵蒂冈之花

这不是必需的,但不使用原型是不好的做法。使用原型,编译器可以验证您正在正确地调用函数(使用正确的参数编号和类型)。没有原型,就有可能拥有以下内容:// file1.cvoid doit(double d){

    ....}int sum(int a, int b, int c){

    return a + b + c;}这是:// file2.c// In C, this is just a declaration and not a prototypevoid doit();int sum();int main(int argc, char *argv[]){

    char idea[] = "use prototypes!";

    // without the prototype, the compiler will pass a char *

    // to a function that expects a double

    doit(idea);

    // and here without a prototype the compiler allows you to

    // call a function that is expecting three argument with just

    // one argument (in the calling function, args b and c will be

    // random junk)

    return sum(argc);}