Search
 
SCRIPT & CODE EXAMPLE
 

C

What should main() return in C?

The accepted answer appears to be targetted for C++, so I thought I'd add an
answer that pertains to C, and this differs in a few ways. There were also 
some changes made between ISO/IEC 9899:1989 (C90) and ISO/IEC 9899:1999 (C99).

main() should be declared as either:

int main(void)
int main(int argc, char **argv)

Or equivalent. For example, int main(int argc, char *argv[]) is equivalentto 
the second one. In C90, the int return type can be omitted as it is a 
default, but in C99 and newer, the int return type may not be omitted.

If an implementation permits it, main() can be declared in other ways 
(e.g., int main(int argc, char *argv[], char *envp[])), but this makes the 
program implementation defined, and no longer strictly conforming.

The standard defines 3 values for returning that are strictly conforming 
(that is, does not rely on implementation defined behaviour): 0 and
EXIT_SUCCESS for a successful termination, and EXIT_FAILURE for an
unsuccessful termination. Any other values are non-standard and 
implementation defined. In C90, main() must have an explicit return 
statement at the end to avoid undefined behaviour. In C99 and newer, you
may omit the return statement from main(). If you do, and main() finished, 
there is an implicit return 0.

Finally, there is nothing wrong from a standards point of view with calling main() recursively from a C program.
Comment

PREVIOUS NEXT
Code Example
C :: open a file in from terminal 
C :: C special character display 
C :: relational operators in c 
C :: commenting in c 
C :: string in c 
C :: size of int in c 
C :: boolean operators in c++ 
C :: C Syntax of goto Statement 
C :: *= in c 
C :: insse suprafata arabila pe ani 
C :: 2 html 1 javascript 
C :: promt user input C 
C :: c to c convertor 
C :: Multiplying a u64 to u128 in Rust 
C :: resto de division recursiva 
C :: how to find folders from a c program 
C :: epita 
C :: can we update values of a map via traversing 
C :: How to scale all columns in dataframe in R? 
C :: fraction sum c 
C :: uri/beecrowd problem no - 1133 solution in C 
C :: data breach 
C :: command line coursera 
C :: c refresher 
C :: print number in c 
C :: online c compiler 
C :: params in main function in C 
C :: how to compare string in c 
C :: visual studio code 
Dart :: change color of drawer icon flutter 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =