Not necessarily every function, but you should on every function that is expected to return an integer--not specifically zero, but something meaningful to you. We use
return 0; at the end of
main because the OS expects to receive a return value (typically 0 for success, or something else like EXIT_FAILURE) when your program exits.
Functions generally only need to return something if you need them to. If you don't, you generally make them
void functions:
Code:
void printx( int x )
{
printf( "x is %d\n", x );
}
Here our function doesn't really need to return anything, because when we wrote it, we decided we didn't care if it did anything more than just print x. But yes, if your function is expected to return something, then you need to make sure it does so:
Code:
int thisiswrong( int x )
{
if( x == 5 )
printf( "hello world!\n" );
/* not returning something here should generate compiler warnings/errors */
}
Here we're expected to return an int, not doing so is an error.