Home > Store

C++ Without Fear: A Beginner's Guide That Makes You Feel Smart, 2nd Edition

Register your product to gain access to bonus material or receive a coupon.

C++ Without Fear: A Beginner's Guide That Makes You Feel Smart, 2nd Edition


  • Sorry, this book is no longer in print.
Not for Sale



  • Attractive design, inviting graphics, and generous use of conceptual art - all designed to make C++ friendlier and easier for novices
  • Modularizes coverage of the new standard to maximize compatibility; most code examples work with both new and existing compilers
  • A consistently successful book, well positioned for the renewed interest in C++ that will come with the new standard
  • The CD will be replaced with a web link on the Internet.

  • Extensive Instructor's guide as well as chapter power point slides for classroom use.


  • Copyright 2011
  • Edition: 2nd
  • Book
  • ISBN-10: 0-13-267326-6
  • ISBN-13: 978-0-13-267326-6

If you’ve always wanted to learn how to program a computer, or to learn the widely used C++ programming language in particular, C++ Without Fear, Second Edition, offers an ideal way to get you started.

Written with the same approach that earned the first edition rave reviews, the author first emphasizes short, simple examples that are easy to enter; then, within a couple of chapters, he has you creating useful utilities, playing games, and using the computer to solve interesting puzzles. His approach is a welcome departure from many programming texts, which quickly get bogged down in complex and sometimes meaningless examples. You’ll find here, patiently explained and clearly illustrated, everything you need to learn programming quickly, and to have fun doing it!

Yes, programming can be a complex task, and C++ is a language often used by professionals. In fact, many of the coolest games, graphics, and Internet applications are created with C++, and it’s even been used on the Mars rovers. But the language, like the monster pictured on the cover, need not be all that fearsome. Broken down to its essentials, and enhanced by simple examples, practical exercises, and the whys and tricks behind each language feature, you’ll be amazed at the rapid progress you can make.

With C++ Without Fear, Second Edition, you will

  • Learn the basics of C++ programming
  • Get started writing your own programs
  • See how and why each piece of a program does what it does
  • Create useful and reusable program code
  • Understand object-oriented programming–for once explained in simple, down-to-earth terms


While compatible with nearly every version of the C++ language, this second edition has been updated to cover important features of the newest and greatest C++ standard (C++0x). In addition, it now includes

  • Even more figures, examples, and exercises
  • Even more puzzles and games
  • An expanded 75-page language reference
  • Instructions for downloading free C++ software

Whether you wish to learn C++ programming for pleasure, or you’re considering a career in programming, this book is an outstanding choice.



C++ Software
To run the programs included in this book, and to create your own, you will need a C++ compiler. Some compilers are available commercially, such as Microsoft’s Visual C++. Others are available for free. Although availability changes from time to time, as we went to press, a free compiler for Windows may be downloaded from the following website, using the instructions given there:


Please note that, whereas the book is intended to be compatible with a wide range of standard C++ compilers, we cannot guarantee compatibility with every compiler you might come across, especially older ones. Nor can we guarantee that the compiler linked to above is free from defect. The link is provided simply as a good place to start in your search for a compiler that works for you, and one that doesn’t cost anything.

Code Examples and Answers to the Exercises
C++ source code for the examples in the book and answers to the exercises related to those examples, organized by chapter, can be found here.

Sample Content

Online Sample Chapter

C++ Without Fear: Functions

Sample Pages

Download the sample pages (includes Chapter 4 and Index)

Table of Contents

Preface xxiii

Acknowledgments xxix

About the Author xxxi

Chapter 1: Your First C++ Programs 1

Thinking Like a Programmer 1

What’s Different About C++? 7

Building a C++ Program 8

Installing Your Own C++ Compiler 10

Advancing to the Next Print Line 16

Storing Data: C++ Variables 19

Introduction to Data Types 20

A Word about Variable Names and Keywords 28

Chapter 1 Summary 30

Chapter 2: Decisions, Decisions 33

But First, a Few Words about Data Types 33

Decision Making in Programs 34

Introducing Loops 43

True and False in C++ 50

The Increment Operator (++) 51

Statements vs. Expressions 52

Introducing Boolean (Short-Circuit) Logic 53

Introducing the Math Library 57

Chapter 2 Summary 64

Chapter 3: The Handy, All-Purpose “for” Statement 67

Loops Used for Counting 67

Introducing the “for” Loop 68

A Wealth of Examples 70

Compound Statements (Blocks) with “for” 74

Declaring Loop Variables on the Fly 74

Comparative Languages 101: The Basic “For” Statement 79

Chapter 3 Summary 80

Chapter 4: Functions: Many Are Called 83

The Concept of Function 83

The Basics of Using Functions 85

Local and Global Variables 93

Recursive Functions 95

Games and More Games 113

Chapter 4 Summary 115

Chapter 5: Arrays: All in a Row... 117

A First Look at C++ Arrays 117

Initializing Arrays 119

Zero-Based Indexing 119

Strings and Arrays of Strings 128

A Word to the Wise 141

2-D Arrays: Into the Matrix 142

Chapter 5 Summary 143

Chapter 6: Pointers: Getting a Handle on Data 145

What the Heck Is a Pointer, Anyway? 145

The Concept of Pointer 146

Declaring and Using Pointers 148

Swap: Another Function Using Pointers 155

Pointer Arithmetic 161

Pointers and Array Processing 163

Chapter 6 Summary 168

Chapter 7: Strings: Analyzing the Text 169

Text Storage on the Computer 169

It Don’t Mean a Thing If It Ain’t Got That String 171

String-Manipulation Functions 172

Reading String Input 178

Individual Characters vs. Strings 185

The New C++ String Type 189

Other Operations on the string Type 193

Chapter 7 Summary 194

Chapter 8: Files: Electronic Storage 197

Introducing File-Stream Objects 197

How to Refer to Disk Files 199

Text Files vs. “Binary” Files 206

Introducing Binary Operations 208

Chapter 8 Summary 217

Chapter 9: Some Advanced Programming Techniques 221

Command-Line Arguments 221

Function Overloading 227

The do-while Loop 230

The switch-case Statement 232

Multiple Modules 234

Exception Handling: I Take Exception to That! 237

Chapter 9 Summary 240

Chapter 10: New Features of C++0x 243

Overview of C++0x Features 243

The long long Type (not long long long) 244

Range-Based “for” (For Each) 256

The auto and decltype Keywords 261

The nullptr Keyword 262

Strongly Typed Enumerations 263

Raw String Literals 273

Chapter 10 Summary 273

Chapter 11: Introducing Classes: The Fraction Class 277

Object Orientation: Quasi-Intelligent Data Types 277

Point: A Simple Class 279

Private: Members Only (Protecting the Data) 281

Introducing the Fraction Class 286

Inline Functions 289

Find the Greatest Common Factor 291

Find the Lowest Common Denominator 292

Chapter 11 Summary 305

Chapter 12: Constructors: If You Build It… 307

Introducing Constructors 307

Multiple Constructors (Overloading) 309

C++0x Only: Initializing Members within a Class 309

The Default Constructor–and a Warning 310

C++0x Only: Delegating Constructors 313

C++0x Only: Consistent Initialization 314

Reference Variables and Arguments (&) 321

The Copy Constructor 323

A Constructor from String to Fract 329

Chapter 12 Summary 331

Chapter 13: Operator Functions: Doing It with Class 333

Introducing Class Operator Functions 333

Operator Functions as Global Functions 336

Improve Efficiency with References 338

Working with Other Types 348

The Class Assignment Function (=) 349

The Test-for-Equality Function (==) 350

A Class “Print” Function 351

C++0x Only: User-Defined Literals 357

Chapter 13 Summary 360

Chapter 14: Dynamic Memory and the String Class 363

Dynamic Memory: The “new” Keyword 363

Objects and “new” 365

Allocating Multiple Data 366

Introducing Class Destructors 370

 “Deep” Copying and the Copy Constructor 376

The “this” Keyword 378

Revisiting the Assignment Operator 379

Writing a Concatenation Function 380

Chapter 14 Summary 387

Chapter 15: Two Complete OOP Examples 389

Introducing Linked Lists 389

Tower of Hanoi, Animated 402

Chapter 15 Summary 411

Chapter 16: Easy Programming with STL 413

Introducing the List Template 413

Designing an RPN Calculator 422

Correct Interpretation of Angle Brackets 432

Chapter 16 Summary 432

Chapter 17: Inheritance: What a Legacy 435

How to Subclass 435

Problems with the FloatFraction Class 440

C++ Only: Inheriting Base-Class Constructors 441

Protected Members 445

Object Containment 447

Safe Inheritance Through Class Hierarchies 448

Chapter 17 Summary 451

Chapter 18: Polymorphism: Object Independence 453

A Different Approach to the FloatFraction Class 453

Virtual Functions to the Rescue! 454

C++ Only: Requiring Explicit Overrides 460

“Pure Virtual” and Other Abstract Matters 461

Abstract Classes and Interfaces 462

Object Orientation and I/O 464

A Final Word (or Two) 470

A Final, Final Word 472

Chapter 18 Summary 472

Appendix A: Operators 475

The Scope (::) Operator 478

The sizeof Operator 478

Old and New Style Type Casts 479

Integer vs. Floating-Point Division 480

Bitwise Operators (&, |, ^, ~, <<, and >>) 480

Conditional Operator 481

Assignment Operators 482

Join (,) Operator 482

Appendix B: Data Types 483

Precision of Data Types 484

Data Types of Numeric Literals 485

String Literals and Escape Sequences 486

Two’s Complement Format for Signed Integers 487

Appendix C: Syntax Summary 491

Basic Expression Syntax 491

Basic Statement Syntax 492

Control Structures and Branch Statements 493

Variable Declarations 498

Function Declarations 500

Class Declarations 502

Enum Declarations 503

Appendix D: Preprocessor Directives 505

The #define Directive 505

The ## Operator (Concatenation) 507

The defined Function 507

The #elif Directive 507

The #endif Directive 508

The #error Directive 508

The #if Directive 508

The #ifdef Directive 509

The #ifndef Directive 510

The #include Directive 510

The #line Directive 511

The #undef Directive 511

Predefined Constants 511

Appendix E: ASCII Codes 513

Appendix F: Standard Library Functions 517

String (C-String) Functions 517

Data-Conversion Functions 517

Single-Character Functions 517

Math Functions 520

Randomization Functions 521

Time Functions 521

Formats for the strftime Function 523

Appendix G: I/O Stream Objects and Classes 525

Console Stream Objects 525

I/O Stream Manipulators 526

Input Stream Functions 528

Output Stream Functions 528

File I/O Functions 529

Appendix H: STL Classes and Objects 531

The STL String Class 531

The <list> Template 533

The <stack> Template 535

Appendix I: Glossary of Terms 537

Index 553

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020