Page 14 - Data Structures Interactive Book
P. 14
Chapter 1
1.1 Basics of C++
C++ is a powerful, general-purpose programming language that evolved from C by
adding features such as classes, objects, and templates. It is widely used in system
programming, application development, and performance-critical software because of its
efficiency and flexibility. The basics of C++ involve understanding how to declare variables,
apply data types, and control program execution. These elements form the foundation of
every program, enabling developers to store information, make decisions, and repeat tasks.
Mastering these basics ensures that students can progress confidently to advanced topics
such as data structures and algorithms.
1.1.1 Variables and Data Types
Variables are symbolic names that represent memory locations where values are
stored. Each variable must be declared with a specific data type, which defines the kind of
data it can hold and the operations that can be performed on it. C++ provides several primitive
data types such as int for integers, float and double for real numbers, char for single
characters, and bool for logical values. Choosing the correct data type is essential for efficient
memory usage and accurate computations. For example, integers are suitable for counting,
while floating-point numbers are used for precise calculations involving fractions.
Common primitive data types include:
• int: stores integers (whole numbers).
• float and double: store real numbers with fractional parts.
• char: stores single characters.
• bool: stores logical values (true or false).
Example:
14

