Declaration and prototype difference

前端 未结 4 2255
盖世英雄少女心
盖世英雄少女心 2021-02-07 11:45

What is the difference between declaration and prototype in C? In which situations they are called declarations and in which prototypes?

4条回答
  •  Happy的楠姐
    2021-02-07 12:25

    According to the C Standard (6.2.1 Scopes of identifiers)

    1. ...(A function prototype is a declaration of a function that declares the types of its parameters.)

    That is a prototype provides the information about the types of the function parameters.

    Consider for example

    void f();
    

    and

    void f( void );
    

    The first declaration is not a prototype because there is nothing known about the function parameters.

    The second declaration is a prototype because it provides a type list of the function parameters (it is a special kind of the type list specifies that the function has no parameters).

提交回复
热议问题