What does main (void) really means, and the purpose of it
![]() |
What does main (void) really means, and the purpose of it
I believe it means that you are effectively not returning anything when a function returns void. Void is an empty data structure that does not have any memory allocated to it.
Hello!
main is the principal structure of any C++ program it normaly have 3 part, usually you will see it like this
int main(void)
{
your code here
return 0
}
-The first part int tell that the main function will return a integer in most case 0 is the return value witch just mean that every thig have work wright but it can also be a other value if a error have occur and your error handling code can use it to return a other value can be useful for deboging reason for example.
- The main part is the main part of your code it is where you will call all your function, it is usually the entry point of your program.
- Now the (void) part it simply mean that your program will not take any argument on is command line when you start your program.
For example you want a program that can take a integer as you start it like
this:
PROGRAM.EXE 234
the structure for your program to accept this value and use it your code will be
something like this
int main(int YourVariableName)
{
HERE YOUR CODE HAVE ACCESS TO YourVariableName
}
Hope this was helpful
All times are GMT -7. The time now is 06:23 PM. |