< Previous | Contents | Next >

Defining the main() Function

The next non-blank line is the header of a function called main().

int main()

A function is a group of programming code that can do some work and return a value. In this case, int indicates that the function will return an integer value. All function headers have a pair of parentheses after the function name.

All Cรพรพ programs must have a function called main(), which is the starting point of the program. The real action begins here.

The next line marks the beginning of the function.

{

And the very last line of the program marks the end of the function.

}

All functions are delimited by a pair of curly braces, and everything between them is part of the function. Code between two curly braces is called a block and is usually indented to show that it forms a unit. The block of code that makes up an entire function is called the body of the function.