C/question about c
Expert: Zlatko - 6/11/2010
Questionhi
I'm the beginner of C programming. i'm confused at the very beginning.... i couldn't understand that why void main() is used? what is void main()? or what is void?
AnswerHello Smile.
You are my first Nepalese questioner!
In C, all code must be in functions. The main function is the first function that is run when a program starts. It is the start of the program.
In C, functions can return values, or they can be written to return nothing. When a function is declared void, it means that the function does not return a value.
The main function should return an integer. That is the C standard. So main should be written like this:
int main()
{
/* Your code goes here */
return 0;
}
The return value is usually 0 for success or 1 for failure, and it can be picked up by the caller of the program, but that is not important for a beginner. Just get into the habit of returning 0 for now.
Some programmers like to add void into the parameter list if the function does not take parameters. I have this habit. That would make main look like this:
int main(void)
{
return 0;
}