answersLogoWhite

0


Best Answer

It returns the value to the operating system or whatever process launched it. If you launched your program from a batch file then the batch file can detect this return value. If your program is spawned or launched by another program then the return value goes to that parent prgoram or process.

One more thing is that you can write main() without the return type and it will be absolutely correct

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why do you have to use the return type for the main function in c language i mean to what does the main function have to return the value to?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the default return type of a function?

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


What is a return statement used for?

It means end the function. Functions automatically end when execution reaches the end of the function, but you can return from a function at any point within the function with a return statement. If the function returns a value to its caller, you must provide a reachable return statement along with the value you wish to return.


What is return in programming?

The return statement is used in functions to return control to the caller. If the function is declared non-void, the return statement also allows the programmer to return a value to the caller.


What data type does the main function return in c?

The main function must return the int data type. A program that terminates normally should return the value zero to indicate no error. Not all execution environments make use of the return value (Windows in particular), however a command script or batch file can examine the ERRORLEVEL if required.


What is significance attached to the main function in C programming?

The main function in C++ is no different to any other function, other than it is the only required function; it defines the entry point of the application. The minimal main function (and therefore the minimal C++ program) is: #include <stdio.h> int main() { return(0); } The main function must always return an integer to the caller (even if not required by the caller). A return value of zero is usually used to indicate the program terminated successfully, however it is up to the programmer to decide what the return value actually means to the caller. It is common to return (-1) upon an unrecoverable error.

Related questions

What is the return type of main?

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


What is the default return type of a function?

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


Where does main returns garbage value?

With return without value, or by dropping off the last statement in the function.


How do you use return?

In C/C++ programming and most other procedural languages, you use a return statement to return control to the calling function. In the case of the global main function, a returnstatement terminates the program, releasing all memory used by the program and returning control to the execution environment.Functions that return void do not return a value and therefore do not require a return statement, unless the function needs to return early (before falling off the end of the function). Functions that return values must use a returnstatement to return the appropriate value to the caller.In C++ (but not in C), the global main function does not require a return statement unless returning early. When omitted, the global main function implicitly returns the value 0 (to the execution environment) when execution falls off the end of the function. To return any other value, a return statement is required.


Why void is restriction in java main function?

becoz the main program doesnot return any value to the os.


What is a return statement used for?

It means end the function. Functions automatically end when execution reaches the end of the function, but you can return from a function at any point within the function with a return statement. If the function returns a value to its caller, you must provide a reachable return statement along with the value you wish to return.


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.


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

No, it should be int type or void.


What is return in programming?

The return statement is used in functions to return control to the caller. If the function is declared non-void, the return statement also allows the programmer to return a value to the caller.


What is the difference between return 0 and return -1 in c?

If we consider any function that is not the main function that is declared as "bool" i.e it will return boolean values to the main function-0 & 1, meaning 'false' and 'true' respectively. If we have to tell the main function that the condition checked in the function is false or disagreed, then we return 0 to the main function and when we have to tell that the condition checked in the main function is true or agreed, then we return 1 to the main function.


What data type does the main function return in c?

The main function must return the int data type. A program that terminates normally should return the value zero to indicate no error. Not all execution environments make use of the return value (Windows in particular), however a command script or batch file can examine the ERRORLEVEL if required.


What is the definition for call by value in c language?

A function is called within a function either called by value or called by reference.When a function is called by passing the values of one or more variables,then the value is copied to a new var of the function's own var of its scope.Ex:void main(){...........c=fun(a,b);...}fun(int c,int d){ int t;t=c+d;return(t);}