# C main() return **[main() return](https://en.cppreference.com/w/c/language/main_function)** value is the program's [[c-exit-status]], communicated to the shell via the `$?` variable. Returning 0 indicates success (`EXIT_SUCCESS`); non-zero indicates failure (`EXIT_FAILURE`, typically 1). The shell can check this status with `echo $?` or use it in conditionals and pipelines. Always explicitly return `EXIT_SUCCESS` or `EXIT_FAILURE` from main to make intent clear. ## Example This example demonstrates returning different exit statuses based on program logic. ```c // compile: gcc -o mainreturn mainreturn.c // run: ./mainreturn 5; echo $? // description: return exit status from main to signal success or failure #include #include int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return EXIT_FAILURE; } int num = atoi(argv[1]); if (num > 0) { printf("Positive number: %d\n", num); return EXIT_SUCCESS; } else { fprintf(stderr, "Error: number must be positive\n"); return EXIT_FAILURE; } } ```