C Program Termination Methods

In C language, a program can be terminated by calling the exit() function. The prototype of the exit() function is located in the stdlib.h header file, and it takes an integer parameter as an exit code, typically 0 for normal exit and other values for abnormal exits. For example:

#include <stdlib.h>

int main() {
    // 正常退出
    exit(0);

    // 异常退出
    exit(1);
}

Additionally, the program can also be terminated by using the return statement, the return statement in the main() function will implicitly call the exit() function. For example:

int main() {
    // 正常退出
    return 0;

    // 异常退出
    return 1;
}
bannerAds