Declare main prototype

前端 未结 5 1622
逝去的感伤
逝去的感伤 2020-11-27 08:11

Is there any reason why I never see main\'s prototype declared in C programs, ie:

int main(int argc, char* argv[]);

int main(int argc, char* argv[])
{
    r         


        
5条回答
  •  青春惊慌失措
    2020-11-27 09:08

    The simple reason being that the control always first go to main.Thus it is automatically located by the compiler thus giving its prototype is redundant and is of no use.

    Also we use prototype when call to a function is made prior to its definition.Thus looking at the function prototype compiler can decide whether call is legitimate or not.But in case of main we are accustomed to provide its definition along with its declaration (which is logically correct also)thus no need of prototype.

    Even when we make our c programs organized into multiple files there is no need for prototype of main.

提交回复
热议问题