You are here:

C/question about c

Advertisement


Question
hi
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?

Answer
Hello 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;
}

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.