C prototype functions

前端 未结 4 1834
予麋鹿
予麋鹿 2020-12-07 02:21

As a beginner to C, I can understand the need for function prototypes in the file, but am unsure of a couple things.

First, does every function call outside of the m

4条回答
  •  忘掉有多难
    2020-12-07 03:09

    No, functions are not required to have prototypes. However, they are useful as they allow functions to be called before they are declared. For example:

    int main(int argc, char **argv)
    {
        function_x(); // undefined function error
        return 0;
    }
    
    void function_x()
    {
    
    }
    

    If you add a prototype above main (this is usually done in a header file) it would allow you to call function_x, even though it's defined after main. This is why when you are using an external library that needs to be linked, you include the header file with all the function prototypes in it.

    C does not have function overloading, so this is irrelevant.

提交回复
热议问题