Chapter 2. The Anatomy of a C++ Program

C++ programs consist of classes, functions, variables, and other component parts. Most of this book is devoted to explaining these parts in depth, but to get a sense of how a program fits together, you must see a complete working program.

In this lesson, you will learn

  • The parts of a C++ program

  • How the parts work together

  • What a function is and what it does

A Simple Program

Even the simple program HELLO.cpp from Lesson 1, “Getting Started,” had many interesting parts. This section reviews this program in more detail. Listing 2.1 reproduces the original version of HELLO.cpp for your convenience.

Example 2.1. HELLO.cpp Demonstrates the Parts of a C++ Program

 1: #include <iostream> 2: 3: int main() 4: { 5: std::cout ...

Get Sams Teach Yourself C++ in One Hour a Day, Sixth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.