return statement | Sololearn: Learn to code for FREE!

return statement

why do we even need the return statement at the end of a C program saying return(0) when we are not using the void function. I mean that I saw programs executing properly even if the return statement is not present.

22nd Nov 2019, 4:17 PM
Paradox - avatar
3 Antworten
+ 3
So that when you run the program, you get a return value (usually as an error code) from it, which can be used outside of the program. It doesn't seem to be used a lot, but well, that's how the language was set up. I think you can - only in the main function - just not write it out, and it will be added for you automatically.
22nd Nov 2019, 4:25 PM
HonFu - avatar
+ 2
You sure it wasn't void function?
22nd Nov 2019, 4:25 PM
Seb TheS
Seb TheS - avatar
+ 2
return gives you back a value, something to be used later instead of just performing an action and printing results to screen but returning nothing.
22nd Nov 2019, 4:29 PM
Inkosi - avatar