Computer Science & C Programming


return statement

  1. In the main declaration, the void corresponds to a special type meaning 'nothing'
  2. This value is the one computed by the program and can be explicitly specified by using the return statement
#include <stdio.h>
void main() {
   printf("Welcome !");
   return;
}

Nb. A return always exit a program (i.e. don't execute instructions after the statement).
3. To improve the program, this one can return the 'status' of the execution: 0=SUCCESS, 1=ERROR

int main() {
   ...
   return 0;
}

Nb. Now the program don't return nothing (void) but a status that is here an int. As a complement, the stdlib.h library define two contant EXIT_SUCCESS and EXIT_FAILURE than can replace 0/1.

#include <stdlib.h>
int main() {
   ...
   return EXIT_SUCCESS;
}

1 - 10