answersLogoWhite

0


Best Answer

It depends on the context.

- it means "no" in functions that check something (like "isatty", "isascii", "isdigit")

- it means "success" in functions whose return value is an error code (0 means no error)

- it means "fail" or "not found" in functions that return a pointer (like strchr or fopen).

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

The declaration int main (...) says that main returns an int. You have to return an int, otherwise the compiler is going to complain. What value int you return is a function of what you want to communicate with the code that called main in the first place. It all a matter of convention. In this particular case, main is called by the startup code in the library which is called by the operating system itself in order to run your program. By convention, the return value of a program is an integer. If the value is zero, then that means that the execution of the program was successful. If it is non-zero, then that means something went wrong, and the specific value is a prearranged value that indicates what went wrong.

In the context of the question, return 0 means that execution was successful and there was no error. In many cases, particularly if the original call was from a shell of some sort, such as cmd or bash, the actual value is not important - what is important is whether or not the program was successful - and error is usually indicated with just a return 1.

Sometimes, however, the return value is important. In the case where a program is called by another program, i.e. as a child process, the parent process might want to know the return value. This can be easily done, because the various CreateProcesstype function setup the ability to retrieve the return value when the program is done.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

You mean: Why return 0 is not mandatory in C++, for function main?

Answer: main is an exception, to make lazy programmers life easier.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Statement. Zero as return value might mean 'no error' (eg: system), or simply 'no' (eg: isatty), or even 'null-pointer' (eg: fopen)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why return 0 is used in int main function in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a prototype within a program?

Prototyping is done (at least in C/C++) to declare a function and tell the compiler how to use it before the int main(void) part of the program is run. The function is declared after main and is usually done as a style thing. example int function(int); int main(void) { int anumber = 1; x = function(anumber); return 0; } int function(int number) { //do something return number; } et cetera et cetera...


Which Keyword is used to return some value from a function?

return var_name; e.g int fun() { int x=...; return x; }


What an example of a function?

In C-programming: int main (void) { return 0; }


Why return 1 is used in int main function in c?

Returning a value of 1 (or any value besides zero) from main indicates an error.


How do you call a function in the main function?

name ( parameters )example:int main (int argc, char **argv){int i;for (i=0; i


What is a function definition in c?

Example: int main (void) { puts ("Here is a function definition"); return 0; }


Can you give an example on how you pass array elements to a function?

int main void (int argc, char *argv[]){int i;for (i=0; i


When is a function executed and where should a function prototype and function definition appear in a source program?

If you want to use prototype it has to be declared before main(). If you have a function of type double with one argument of type int (with name arg), and the function name is func, then we have:#include ...double func(int arg);...int main(...){...return 0;}...double func(int arg){...}


What are the functions of 'C'?

Pieces of program-code, they are identified by their names. Example for function-declaration: int main (void); Example for function-definition: int main (void) { puts ("Hello, world!"); return 0; }


How is main function declared?

int main (void) or int main(int a, char **p)


How you call a function in main?

name ( parameters )example:int main (int argc, char **argv){int i;for (i=0; i


Can you use the float as a return type of the main function in 'C' language?

No, it should be int type or void.