Read this code! my code! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Read this code! my code!

main()

puts("Hellow world") ;

return 0;


I dont know why I put the return statement there with the value of 0, meaning success a tutorial told me.

Should I take out the return statement? Is this function actually returning a value? well, is the value "Hellow wolrd and 'puts' for the main function?

Is that what the main function returns? the words?

What if I put void there, will there be a return statement? What is the value of the function! I did not put a void!


Comments

  • : main()

    : puts("Hellow world") ;

    : return 0;


    : I dont know why I put the return statement there with the value of 0, meaning success a tutorial told me.


    The ANSI standard to the C language essentially says that main must return an integer value to the operating system that called it. Some operating systems don't use this value, but many do. If you define main as returning an integer, then you should return one.


    Unfortunately, in C, it is legal not to have a return type which then defaults to int. You shouldn't do this in my opinion. Specify the return type as int.


    int main(void)

    {

    /*code*/

    return 0;

    }




    You should return 0 if your program is successful. You can return a different value if your program encounters an error during operation and you want the operating system to know this.






    : Should I take out the return statement? Is this function actually returning a value? well, is the value "Hellow wolrd and 'puts' for the main function?


    It is (supposed to be) returning a value. Whatever author wrote the C tutorial you're learning from should be shot. With a nerf weapon, naturally.




    : Is that what the main function returns? the words?


    The main function is supposed to return an int.



    : What if I put void there, will there be a return statement? What is the value of the function! I did not put a void!


    If you put a void as the return type for main, you can still do a return, but without anything (return;). If the code reaches the end of a routine it will return on its own.


    However, you really shouldn't define main as returning void. The operating system will probably get a garbage value back as an error code, and this will cause different behaviour on different systems, like as not.







Sign In or Register to comment.