So what does “return 0” actually mean?

后端 未结 6 611
谎友^
谎友^ 2020-12-08 12:02

I\'m pretty proficient in PHP, but I\'ve started dabbling with C. I\'ve seen the code

return 0;

at the end of functions that don\'t return

6条回答
  •  悲&欢浪女
    2020-12-08 12:38

    In C you don't have to return a value only if you declare a function with void at the start of it. First example:

    #include 
     int main()
    {
       printf("Hello World!");
        return 0; // you have to use return because main starting with int
    }
    

    Second Example:

    #include 
    void main()
    {
    printf("Hello World!");
    //in this case return is useless, main is a void function
    
    }
    

提交回复
热议问题