Data Structures and Algorithms in C++, Second Edition
by Michael T. Goodrich, Roberto Tamassia, David M. Mount
Chapter 1. A C++ Primer

Contents
1.1 Basic C++ Programming Elements | 2 |
1.1.1 A Simple C++ Program | 2 |
1.1.2 Fundamental Types | 4 |
1.1.3 Pointers, Arrays, and Structures | 7 |
1.1.4 Named Constants, Scope, and Namespaces | 13 |
1.2 Expressions | 16 |
1.2.1 Changing Types through Casting | 20 |
1.3 Control Flow | 23 |
1.4 Functions | 26 |
1.4.1 Argument Passing | 28 |
1.4.2 Overloading and Inlining | 30 |
1.5 Classes | 32 |
1.5.1 Class Structure | 33 |
1.5.2 Constructors and Destructors | 37 |
1.5.3 Classes and Memory Allocation | 40 |
1.5.4 Class Friends and Class Members | 43 |
1.5.5 The Standard Template Library | 45 |
1.6 C++ Program and File Organization | 47 |
1.6.1 An Example Program | 48 |
1.7 Writing a C++ Program | 53 |
1.7.1 Design | 54 |
1.7.2 Pseudo-Code | 54 |
1.7.3 Coding | 55 |
1.7.4 Testing and Debugging | 57 |
1.8 Exercises | 60 |
Basic C++ Programming Elements
Building data structures and algorithms requires communicating instructions to a computer, and an excellent way to perform such communication is using a high-level computer language, such as C++. C++ evolved from the programming language C, and has, over time, undergone further evolution and development from its original definition. It has incorporated many features that were not part of C, such as symbolic constants, in-line function substitution, reference types, parametric polymorphism through templates, and exceptions (which are discussed later). As a result, C++ has grown to be a complex programming language. Fortunately, we do not need to know ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access