die, exit () and return the difference

die () and exit () is abort script execution function; in fact die exit and the two names pointing to the same function, die () is an alias for exit () function. The function takes a single argument, the program may be a return value or a string, the input parameters may not result no return value.

When a program error, a string can be passed to it, it is output on the terminal systems usually use die () name.

$ Fp = fopen ( "./ readme.txt", "r") or die ( "can not open the file");


  1. die (): stop the program run, output content

    exit: stop the program run, not content output

    return: return to duty

  1. die: an error is encountered stopped

    exit: direct stopped, and the subsequent code is not running, Exit () may display the content.

    return: the return value is pure, but it will not run subsequent code

  1. exit (0): normal operation of the program and exit the program;

    exit (1): abnormal operation leading to exit the program;

    return (): function that returns, if the main function, the function exits and will return a value.



  1. return function return value is a keyword; exit is a function; Die is a function.

  2. return is the language level, which represents a return call stack; and exit system call level, it represents the end of a process.

  3. return is the exit function (returns); exit is the exit process.

  4. return is provided by the C language, exit is provided by the operating system (or a given library).

  5. return for ending the execution of a function, the function execution information outgoing calls other functions use;

      exit function is to exit the application, a state of the memory space using the delete process, and the application returns to the OS, the state identified a number of operational information about the application, and the information machines and operating systems, generally is 0 for normal exit non-zero non-normal exit.

  6. Non main function call return and exit effect is obvious, but the call return and exit of the main function is very vague phenomenon, the phenomenon in many cases are the same

Guess you like

Origin www.cnblogs.com/coderMap/p/11294343.html