1 C++ A Beginner’s Guide by Herbert Schildt
Module 2 Introducing Data Types and Operators Table of Contents CRITICAL SKILL 2.1: The C++ Data Types ....................................................................................................... 2
Project 2-1 Talking to Mars ......................................................................................................................... 10
CRITICAL SKILL 2.2: Literals ......................................................................................................................... 12
CRITICAL SKILL 2.3: A Closer Look at Variables ........................................................................................... 15
CRITICAL SKILL 2.4: Arithmetic Operators ................................................................................................... 17
CRITICAL SKILL 2.5: Relational and Logical Operators ................................................................................ 20
Project 2-2 Construct an XOR Logical Operation ........................................................................................ 22
CRITICAL SKILL 2.6: The Assignment Operator ........................................................................................... 25
CRITICAL SKILL 2.7: Compound Assignments .............................................................................................. 25
CRITICAL SKILL 2.8: Type Conversion in Assignments ................................................................................. 26
CRITICAL SKILL 2.9: Type Conversion in Expressions .................................................................................. 27
CRITICAL SKILL 2.10: Casts........................................................................................................................... 27
CRITICAL SKILL 2.11: Spacing and Parentheses ........................................................................................... 28
Project 2-3 Compute the Regular Payments on a Loan .............................................................................. 29
At the core of a programming language are its data types and operators. These elements define the
limits of a language and determine the kind of tasks to which it can be applied. As you might expect, C++
supports a rich assortment of both data types and operators, making it suitable for a wide range of
programming. Data types and operators are a large subject. We will begin here with an examination of
C++’s foundational data types and its most commonly used operators. We will also take a closer look at
variables and examine the expression.