next up previous
Next: Console Output Up: Overview of C++ Previous: Header Files

Functions

All C++ programs are composed of one or more functions. Every C++ function must have a name, and the only function that any C++ program must include is the
\begin{emph}
main() \end{emph}
. Most C++ programs starts with a call to
\begin{emph}
main() \end{emph}
and in most cases ends when
\begin{emph}
main() \end{emph}
returns. The opening curly { brace on the line that follows
\begin{emph}
main() \end{emph}
marks the start of the
\begin{emph}
main() \end{emph}
function.


\begin{emph}
return 0; \end{emph}
terminates
\begin{emph}
main() \end{emph}
and cause it to return the value 0 to the calling process. For most operating systems, a return value of 0 signifies that the program is terminating normally.
\begin{emph}
return \end{emph}
is one of C++ keywords, and it is used to return a value from a function. It will be discussed later in more details. For now your programs should return 0 when they terminate normally.

The closing curly brace } at the end of the program formally concludes the program. Although the brace is not actually a apart of the object code of the program, conceptually you can think of a C++ program ending when the closing curly brace of
\begin{emph}
main() \end{emph}
is executed. In fact, if the
\begin{emph}
return \end{emph}
statement were not part of this program , the program would automatically end when the closing surly brace was encountered.


next up previous
Next: Console Output Up: Overview of C++ Previous: Header Files
Yousef Haik
2/23/1998