Programs

A program is a collection of functions. One of those functions must have the name main(). When program execution begins, main() will be called automatically, together with any parameters. The function main() must return an int.

The Function main()

After main() has been defined, the UnderC command #r (that is, run) causes a new console window to be created, showing the output generated by the program (see Figure 4.1), as in the following example:

;> int main() {
;1} cout << "Hello World\n";
;1} return 0;
;1} }
;> #r
Figure 4.1. An example of the output generated by the program.

If main() is not defined, #r produces a “cannot find 'main' ...

Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.