0

Is return 0 still important in the main function?

#include <stdio.h>
int main()
{
   printf("Hello, World!");
   return 0; 
}
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
Abdallah
  • 15
  • 8
  • 2
    Strictly speaking `return 0;` (which should be `return EXIT_SUCCESS;` imo) is entirely optional, but only in the `main` method: https://stackoverflow.com/questions/4138649/why-is-return-0-optional – Dai Oct 24 '22 at 22:51
  • 1
    You could `#include ` and have `return EXIT_SUCCESS;` instead (q.v. [exit status](https://en.cppreference.com/w/c/program/EXIT_status).) – Eljay Oct 24 '22 at 22:51
  • @Dai Returning zero or `EXIT_SUCCESS` is equivalent. C17 7.22.4.4 "If the value of status is zero or `EXIT_SUCCESS`, an implementation-defined form of the status successful termination is returned." So running around changing `return 0` in main() into `return EXIT_SUCCESS` is completely senseless. The only thing achieved by that would be an opportunity for posing of obscure knowledge regarding useless details in the C spec. Furthermore, good programmers don't make the code needlessly complex just for the heck of it. – Lundin Oct 25 '22 at 07:47

0 Answers0