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).
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.
You mean: Why return 0 is not mandatory in C++, for function main?
Answer: main is an exception, to make lazy programmers life easier.
Statement. Zero as return value might mean 'no error' (eg: system), or simply 'no' (eg: isatty), or even 'null-pointer' (eg: fopen)
return var_name; e.g int fun() { int x=...; return x; }
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){...}
int main (void) or int main(int a, char **p)
The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value. In C++ language, the main() function can be left without return value. By default, it will return zero. To learn more about data science please visit- Learnbay.co
#include <stdio.h> int main (int argc, char **argv) { puts (argv[0]); return 0; }
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...
return var_name; e.g int fun() { int x=...; return x; }
In C-programming: int main (void) { return 0; }
Returning a value of 1 (or any value besides zero) from main indicates an error.
name ( parameters )example:int main (int argc, char **argv){int i;for (i=0; i
Example: int main (void) { puts ("Here is a function definition"); return 0; }
int main void (int argc, char *argv[]){int i;for (i=0; i
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){...}
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; }
int main (void) or int main(int a, char **p)
name ( parameters )example:int main (int argc, char **argv){int i;for (i=0; i
No, it should be int type or void.