Why is void main used in c




















Void is a return type which is used before a function for defining that the function is returning no value. So it is no needed that we put a return type before main.. So we do put a void return type before main in our program. Anonymous answered. You must have read about Functions in C. Every Function in C returns a value to the Calling Function.

You must have already seen this. Whenever you called a function by passing its arguments, it tells the calling function a value in return.

For example, if you are programming a game suppose hangman, you may wish to make a separate C file that stores the number of wrong alphabets entered, suppose 'Misses'. If so, later you'll need to call the 'main ' of 'Misses' in your final file.

I am a Tutor. Sorry, this phone number is not verified, Please login with your email Id. By signing up, you agree to our Terms of Use and Privacy Policy. Over 55 lakh students rely on UrbanPro. Using UrbanPro. More than 7. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you.

Read more. Post your Learning Need Signup as a Tutor. What is void main into main and what it does? Syntax of main function Void means nothing or empty. Void is return type of function. Comments Dislike Bookmark.

The void is a data type which tells to compile; it is a return type of the main function. The main is a predefined function which is the entry point of every program. Void main is the entry gate of the program when you run the program then this is called first by the compiler. Void main is a function which does not return any value. Or in the simple form, it is null so we can return anything. When nothing is to be returned from the main function, we write void main because void is taken as NULL.

When the value to be returned is in integer format, we write int main. The main is a function from where any C Program starts execution and void is a keyword which is used in the place of function's return type which means the function will not return any value at the point Main is the function from where program execution starts.

And the void is the empty return type. C has statically typed programming language before sending I hope this will clear your doubt. If not, try to practice on the same and learn from errors. Happy Coding : read less. Related Questions. Check out our Data Structures in C course to start learning today. In that case, the value returned is 0, meaning successful execution.

If you write the whole error-free main function without a return statement at the end then the compiler automatically adds a return statement with proper datatype at the end of the program. It may be allowed by some compilers though. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Skip to content. Hence the function does not return any value to the Operating system after its execution, that is on exit. Since no value is returned back to the Operating system, there is no method to know if the program ran successfully or not. Here, the return type of main is int. That is the function ideally expects a return type value int integer to be passed to it. Hence, the return statement; which returns value 0 to main on completion of the program.

In C, empty functions , accept any number of arguments; i. In this case, any number of arguments will be accepted by the function.



0コメント

  • 1000 / 1000