For example consider following code:
int main(int argc,char *argv[])
{
int *p,*q;
p = (int *)malloc(sizeof(int)*10);
q = (int *)malloc(sizeof(int)*1
As explained here, in the context of main both return and exit do the same thing
Q: Why do we need to return or exit?
A: To indicate execution status.
In your example even if you didnt have return or exit statements the code would run fine (Assuming everything else is syntactically,etc-ally correct. Also, if (and it should be) main returns int you need that return 0 at the end).
But, after execution you don't have a way to find out if your code worked as expected.
You can use the return code of the program (In *nix environments , using $?) which gives you the code (as set by exit or return) . Since you set these codes yourself you understand at which point the code reached before terminating.
You can write return 123 where 123 indicates success in the post execution checks.
Usually, in *nix environments 0 is taken as success and non-zero codes as failures.