Quick Google Search

Mistakes in the main( ) function.

 Many people mishandle the  main( )  function. You can avoid such mishandling by
setting your compiler to ANSI C standard so that it will point out the error.

5.1 What main( ) returns?
  main( )  should return 0 or 1. If it returns 0 to the operation system, the operating
system will understand that the program is successfully executed. If it returns 1, the operating
system will understand that the program is terminated with error. So  main( )  should not  be
declared as void.
  main( ) should be declared as

 int main( void )
  {
   :
   :
   return ( 0 );  /* or return( EXIT_SUCCESS ); */
  }

5.2 Arguments of main( )
main( ) should be declared without any arguments or with two arguments:

a) int main( void )
or
b)  int main( int argc, char *argv[] )

5.3 exit( )
  The statement exit( ) also returns values to the operating system as the return( ) in
main( ). The exit takes only two values 0 and 1. (Many people use exit(2), exit(3)….
All these are wrong!)
 So exit should be used as:

a) For normal termination  exit( 0 ); or exit( EXIT_SUCCESS);
b) For abnormal termination  exit( 1 ); or exit( EXIT_FAILURE);

No comments:

Popular Posts