Difference between return 1, return 0, return -1 and exit?

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)*10);
   if (p == 0)
{
    printf("ERROR: Out of memory\n");
        return 1;
}


   if (q == 0)
{
    printf("ERROR: Out of memory\n");
        exit(0);
}

   return 0;
}

What does return 0, return 1, exit(0) do in the above program? exit(0) will exit total program and control comes out of loop but what happens in case of return 0, return 1, return -1.


return from main() is equivalent to exit

the program terminates immediately execution with exit status set as the value passed to return or exit

return in an inner function (not main) will terminate immediately the execution of the specific function returning the given result to the calling function.

exit from anywhere on your code will terminate program execution immediately.


status 0 means the program succeeded.

status different from 0 means the program exited due to error or anomaly.

If you exit with a status different from 0 you're supposed to print an error message to stderr so instead of using printf better something like

if(errorOccurred) {
    fprintf(stderr, "meaningful message here\n");
    return -1;
}

note that (depending on the OS you're on) there are some conventions about return codes.

Google for "exit status codes" or similar and you'll find plenty of information on SO and elsewhere.


Worth mentioning that the OS itself may terminate your program with specific exit status codes if you attempt to do some invalid operations like reading memory you have no access to.

Extend SAP 'features' with ABAP code, One of the powerful tools for configuring SAP HR is features – structured decision logic that looks at status = 0. ELSE. * this is how we return an error condition status = 2. ENDIF. ENDFORM. According to this code, if the value of struc-field1 is value1, then the feature returns a value of RETURN1. Leave this field blank 


return n from your main entry function will terminate your process and report to the parent process (the one that executed your process) the result of your process. 0 means SUCCESS. Other codes usually indicates a failure and its meaning.

mivaecommerce/mivascript-snippets · GitHub, At Tastardo, all products are custom made, we do not accept returns. However, in the rare event that the shirt you ordered is different than the one you receive or 


To indicate execution status.

status 0 means the program succeeded.

status different from 0 means the program exited due to error or anomaly.

return n; from your main entry function will terminate your process and report to the parent process (the one that executed your process) the result of your process. 0 means SUCCESS. Other codes usually indicates a failure and its meaning.

Return Policy Of Tastardo | Return and Refund Policy, jdelaney has write d{2,2}, why there is a difference? Tips: mode 3 for stringregexp() will return all the results as an array, and adding (?i) in 


return n from main is equivalent to exit(n).

The valid returned is the rest of your program. It's meaning is OS dependent. On unix, 0 means normal termination and non-zero indicates that so form of error forced your program to terminate without fulfilling its intended purpose.

It's unusual that your example returns 0 (normal termination) when it seems to have run out of memory.

Format of a string - AutoIt General Help and Support, PRIMARY RETURN/REASON CODES. return1/reason1. DO NOT MATCH For assistance, contact Technical Support. Common Nucleus Messages. Products 


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.

1297S, I need get the output of a VARCHAR2 variable in PRO*C. This variable comes But the syntax does not allow me to have zero parameters, it demands a case declare end exception exit for goto if loop mod null pragma raise return select Oracle SQL PL/SQL: use return value of function as input for another function?


Print varchar in Pro*c from Oracle Procedure - oracle - iOS, IBM R12.0 BUG 4794 OS * * THIS BUG FIX DEPENDS ON FFD 4 DISTRIBUTION AS *15* 00385000 MVI STATUS,#URBSNOR SET UP FOR EXIT. EQU * *05​* 00037180 B RETURN1 RETURN TO CALLER *05* 00038010 * INSERT THE 


IBM R12.0 BUG 4794 OS * * THIS BUG FIX DEPENDS ON FFD 4 , ✓Limited Time Sale ✓Easy Return. 4X20 Airsoft Gamo Telescopic Sights Outdoor Tactical Hunting Optics for .22 Caliber Air -Exit pupil: 4.4mm-13.3mm


Free Shipping Super 3 9X32 Tri Rail MR33 Long Range Airsoft , Army Shotgun Rifle Sniper Scope Tactical Red Dot & Green Dot Illuminated Sight Scope Enjoy ✓Free Shipping Worldwide! ✓Limited Time Sale ✓Easy Return.