Home > Store

C: How to Program, 6th Edition

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

C: How to Program, 6th Edition

Book

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

About

Features

Signature “Live Code™ Approach” — Language features are presented in the context of a wide variety of complete working programs.

— Features thousands of lines of code in hundreds of complete working programs.

— Enables students to confirm that programs run as expected. — Students can also manipulate the code from the book's Companion Website (www.prenhall.com/deitel) or from the author's website (www.deitel.com).

Outstanding, consistent and applied pedagogy:

— Icons throughout identify Software Engineering Observations; Good Programming Practices; Common Programming Errors; Portability Tips; Performance Tips, Testing and Debugging Tips, and Look-and-Feel Observations.

— Provides hundreds of valuable programming tips and facilitates learning.

• Extensive set of interesting exercises and substantial projects.

— Enables students to apply what they've learned in each chapter.

Description

  • Copyright 2010
  • Edition: 6th
  • Book
  • ISBN-10: 0-13-612356-2
  • ISBN-13: 978-0-13-612356-9

C How to Program, 6e, is ideal for introductory courses in C Programming. Also for courses in Programming for Engineers, Programming for Business, and Programming for Technology. This text provides a valuable reference for programmers and anyone interested in learning the C programming language. 

The Deitels' groundbreaking How to Program series offers unparalleled breadth and depth of object-oriented programming concepts and intermediate-level topics for further study.


Using the Deitels’ signature “Live-Code™ Approach,” this complete, authoritative introduction to C programming offers strong treatment of structured algorithm and program development in ANSI/ISO C with 150 working C programs. Includes rich, 300-page treatment of object-oriented programming in C++ that helps readers interpret the code more effectively.

Sample Content

Table of Contents

Preface

1 Introduction to Computers, the Internet and the Web

1.1 Introduction

1.2 Computers: Hardware and Software

1.3 Computer Organization

1.4 Personal, Distributed and Client/Server Computing

1.5 The Internet and the World Wide Web

1.6 Machine Languages, Assembly Languages and High-Level Languages

1.7 History of C

1.8 C Standard Library

1.9 C++

1.10 Java

1.11 Fortran, COBOL, Pascal and Ada

1.12 BASIC, Visual Basic, Visual C++, C# and .NET

1.13 Key Software Trend: Object Technology

1.14 Typical C Program Development Environment

1.15 Hardware Trends

1.16 Notes About C and This Book

1.17 Web Resources

2 Introduction to C Programming

2.1 Introduction

2.2 A Simple C Program: Printing a Line of Text

2.3 Another Simple C Program: Adding Two Integers

2.4 Memory Concepts

2.5 Arithmetic in C

2.6 Decision Making: Equality and Relational Operators

3 Structured Program Development in C

3.1 Introduction

3.2 Algorithms

3.3 Pseudocode

3.4 Control Structures

3.5 The if Selection Statement

3.6 The if…else Selection Statement

3.7 The while Repetition Statement

3.8 Formulating Algorithms Case Study 1: Counter-Controlled Repetition

3.9 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition

3.10 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 3: Nested Control Structures

3.11 Assignment Operators

3.12 Increment and Decrement Operators

4 C Program Control

4.1 Introduction

4.2 Repetition Essentials

4.3 Counter-Controlled Repetition

4.4 for Repetition Statement

4.5 for Statement: Notes and Observations

4.6 Examples Using the for Statement

4.7 switch Multiple-Selection Statement

4.8 do…while Repetition Statement

4.9 break and continue Statements

4.10 Logical Operators

4.11 Confusing Equality (==) and Assignment (=) Operators

4.12 Structured Programming Summary

5 C Functions

5.1 Introduction

5.2 Program Modules in C

5.3 Math Library Functions

5.4 Functions

5.5 Function Definitions

5.6 Function Prototypes

5.7 Function Call Stack and Activation Records

5.8 Headers

5.9 Calling Functions By Value and By Reference

5.10 Random Number Generation

5.11 Example: A Game of Chance

5.12 Storage Classes

5.13 Scope Rules

5.14 Recursion

5.15 Example Using Recursion: Fibonacci Series

5.16 Recursion vs. Iteration

6 C Arrays

6.1 Introduction

6.2 Arrays

6.3 Defining Arrays

6.4 Array Examples

6.5 Passing Arrays to Functions

6.6 Sorting Arrays

6.7 Case Study: Computing Mean, Median and Mode Using Arrays

6.8 Searching Arrays

6.9 Multiple-Subscripted Arrays

7 C Pointers

7.1 Introduction

7.2 Pointer Variable Definitions and Initialization

7.3 Pointer Operators

7.4 Passing Arguments to Functions by Reference

7.5 Using the const Qualifier with Pointers

7.6 Bubble Sort Using Call-by-Reference

7.7 sizeof Operator

7.8 Pointer Expressions and Pointer Arithmetic

7.9 Relationship between Pointers and Arrays

7.10 Arrays of Pointers

7.11 Case Study: Card Shuffling and Dealing Simulation

7.12 Pointers to Functions

8 C Characters and Strings

8.1 Introduction

8.2 Fundamentals of Strings and Characters

8.3 Character-Handling Library

8.4 String-Conversion Functions

8.5 Standard Input/Output Library Functions

8.6 String-Manipulation Functions of the String-Handling Library

8.7 Comparison Functions of the String-Handling Library

8.8 Search Functions of the String-Handling Library

8.9 Memory Functions of the String-Handling Library

8.10 Other Functions of the String-Handling Library

9 C Formatted Input/Output

9.1 Introduction

9.2 Streams

9.3 Formatting Output with printf

9.4 Printing Integers

9.5 Printing Floating-Point Numbers

9.6 Printing Strings and Characters

9.7 Other Conversion Specifiers

9.8 Printing with Field Widths and Precision

9.9 Using Flags in the printf Format Control String

9.10 Printing Literals and Escape Sequences

9.11 Reading Formatted Input with scanf

10 C Structures, Unions, Bit Manipulations and Enumerations

10.1 Introduction

10.2 Structure Definitions

10.3 Initializing Structures

10.4 Accessing Structure Members

10.5 Using Structures with Functions

10.6 typedef

10.7 Example: High-Performance Card Shuffling and Dealing Simulation

10.8 Unions

10.9 Bitwise Operators

10.10 Bit Fields

10.11 Enumeration Constants

11 C File Processing

11.1 Introduction

11.2 Data Hierarchy

11.3 Files and Streams

11.4 Creating a Sequential-Access File

11.5 Reading Data from a Sequential-Access File

11.6 Random-Access Files

11.7 Creating a Random-Access File

11.8 Writing Data Randomly to a Random-Access File

11.9 Reading Data from a Random-Access File

11.10 Case Study: Transaction-Processing Program

12 C Data Structures

12.1 Introduction

12.2 Self-Referential Structures

12.3 Dynamic Memory Allocation

12.4 Linked Lists

12.5 Stacks

12.6 Queues

12.7 Trees

13 C Preprocessor

13.1 Introduction

13.2 #include Preprocessor Directive

13.3 #define Preprocessor Directive: Symbolic Constants

13.4 #define Preprocessor Directive: Macros

13.5 Conditional Compilation

13.6 #error and #pragma Preprocessor Directives

13.7 # and ## Operators

13.8 Line Numbers

13.9 Predefined Symbolic Constants

13.10 Assertions

14 Other C Topics

14.1 Introduction

14.2 Redirecting I/O

14.3 Variable-Length Argument Lists

14.4 Using Command-Line Arguments

14.5 Notes on Compiling Multiple-Source-File Programs

14.6 Program Termination with exit and atexit

14.7 volatile Type Qualifier

14.8 Suffixes for Integer and Floating-Point Constants

14.9 More on Files

14.10 Signal Handling

14.11 Dynamic Memory Allocation: Functions calloc and realloc

14.12 Unconditional Branching with goto

15 C++ as a Better C; Introducing Object Technology

15.1 Introduction

15.2C++

15.3 A Simple Program: Adding Two Integers

15.4 C++ Standard Library

15.5 Header Files

15.6 Inline Functions

15.7 References and Reference Parameters

15.8 Empty Parameter Lists

15.9 Default Arguments

15.10 Unary Scope Resolution Operator

15.11 Function Overloading

15.12 Function Templates

15.13 Introduction to Object Technology and the UML

15.14 Wrap-Up

16 Introduction to Classes and Objects

16.1 Introduction

16.2 Classes, Objects, Member Functions and Data Members

16.3 Defining a Class with a Member Function

16.4 Defining a Member Function with a Parameter

16.5 Data Members, set Functions and get Functions

16.6 Initializing Objects with Constructors

16.7 Placing a Class in a Separate File for Reusability

16.8 Separating Interface from Implementation

16.9 Validating Data with set Functions

16.10 Wrap-Up

17 Classes: A Deeper Look, Part 1

17.1 Introduction

17.2 Time Class Case Study

17.3 Class Scope and Accessing Class Members

17.4 Separating Interface from Implementation

17.5 Access Functions and Utility Functions

17.6 Time Class Case Study: Constructors with Default Arguments

17.7 Destructors

17.8 When Constructors and Destructors are Called

17.9 Time Class Case Study: A Subtle Trap–Returning a Reference to a

private Data Member

17.10 Default Memberwise Assignment

17.11 Wrap-Up

18 Classes: A Deeper Look, Part 2

18.1 Introduction

18.2 const (Constant) Objects and const Member Functions

18.3 Composition: Objects as Members of Classes

18.4 friend Functions and friend Classes

18.5 Using the this Pointer

18.6 static Class Members

18.7 Data Abstraction and Information Hiding

18.8 Wrap-Up

19 Operator Overloading

19.1 Introduction

19.2 Fundamentals of Operator Overloading

19.3 Restrictions on Operator Overloading

19.4 Operator Functions as Class Members vs. Global Function

19.5 Overloading Stream Insertion and Stream Extraction Operators

19.6 Overloading Unary Operators

19.7 Overloading Binary Operators

19.8 Dynamic Memory Management

19.9 Case Study: Array Class

19.10 Converting between Types

19.11 Building a String Class

19.12 Overloading ++ and --

19.13 Case Study: A Date Class

19.14 Standard Library Class string

19.15 explicit Constructors

19.16 Proxy Classes

19.17 Wrap-Up

20 Object-Oriented Programming: Inheritance

20.1 Introduction

20.2 Base Classes and Derived Classes

20.3 protected Members

20.4 Relationship between Base Classes and Derived Classes

20.4.1 Creating and Using a CommissionEmployee Class

20.4.2 Creating a BasePlusCommissionEmployee Class Without Using Inheritance

20.4.3 Creating a CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy

20.4.4 CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data

20.4.5 CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy Using private Data

20.5 Constructors and Destructors in Derived Classes

20.6 public, protected and private Inheritance

20.7 Software Engineering with Inheritance

20.8 Wrap-Up

21 Object-Oriented Programming: Polymorphism

21.1 Introduction

21.2 Polymorphism Examples

21.3 Relationships Among Objects in an Inheritance Hierarchy

21.3.1 Invoking Base-Class Functions from Derived-Class Objects

21.3.2 Aiming Derived-Class Pointers at Base-Class Objects

21.3.3 Derived-Class Member-Function Calls via Base-Class Pointers

21.3.4 Virtual Functions

21.3.5 Summary of the Allowed Assignments Between Base-Class and Derived-Class Objects and Pointers

21.4 Type Fields and switch Statements

21.5 Abstract Classes and Pure virtual Functions

21.6 Case Study: Payroll System Using Polymorphism

21.6.1 Creating Abstract Base Class Employee

21.6.2 Creating Concrete Derived Class SalariedEmployee

21.6.3 Creating Concrete Derived Class HourlyEmployee

21.6.4 Creating Concrete Derived Class CommissionEmployee

21.6.5 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee

21.6.6 Demonstrating Polymorphic Processing

21.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”

21.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info

21.9 Virtual Destructors

21.10 Wrap-Up

22 Templates

22.1 Introduction

22.2 Function Templates

22.3 Overloading Function Templates

22.4 Class Templates

22.5 Nontype Parameters and Default Types for Class Templates

22.6 Notes on Templates and Inheritance

22.7 Notes on Templates and Friends

22.8 Notes on Templates and static Members

22.9 Wrap-Up

23 Stream Input/Output

23.1 Introduction

23.2 Streams

23.2.1 Classic Streams vs. Standard Streams

23.2.2 iostream Library Header Files

23.2.3 Stream Input/Output Classes and Objects

23.3 Stream Output

23.3.1 Output of char * Variables

23.3.2 Character Output Using Member Function put

23.4 Stream Input

23.4.1 get and getline Member Functions

23.4.2 istream Member Functions peek, putback and ignore

23.4.3 Type-Safe I/O

23.5 Unformatted I/O Using read, write and gcount

23.6 Introduction to Stream Manipulators

23.6.1 Integral Stream Base: dec, oct, hex and setbase

23.6.2 Floating-Point Precision (precision, setprecision)

23.6.3 Field Width (width, setw)

23.6.4 User-Defined Output Stream Manipulators

23.7 Stream Format States and Stream Manipulators

23.7.1 Trailing Zeros and Decimal Points (showpoint)

23.7.2 Justification (left, right and internal)

23.7.3 Padding (fill, setfill)

23.7.4 Integral Stream Base (dec, oct, hex, showbase)

23.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)

23.7.6 Uppercase/Lowercase Control (uppercase)

23.7.7 Specifying Boolean Format (boolalpha)

23.7.8 Setting and Resetting the Format State via Member Function flags

23.8 Stream Error States

23.9 Tying an Output Stream to an Input Stream

23.10 Wrap-Up

24 Exception Handling

24.1 Introduction

24.2 Exception-Handling Overview

24.3 Example: Handling an Attempt to Divide by Zero

24.4 When to Use Exception Handling

24.5 Rethrowing an Exception

24.6 Exception Specifications

24.7 Processing Unexpected Exceptions

24.8 Stack Unwinding

24.9 Constructors, Destructors and Exception Handling

24.10 Exceptions and Inheritance

24.11 Processing new Failures

24.12 Class auto_ptr and Dynamic Memory Allocation

24.13 Standard Library Exception Hierarchy

24.14 Other Error-Handling Techniques

24.15 Wrap-Up

A Operator Precedence Charts

B ASCII Character Set

C Number Systems

C.1 Introduction

C.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers

C.3 Converting Octal and Hexadecimal Numbers to Binary Numbers

C.4 Converting from Binary, Octal or Hexadecimal to Decimal

C.5 Converting from Decimal to Binary, Octal or Hexadecimal

C.6 Negative Binary Numbers: Two’s Complement Notation

D Game Programming: Solving Sudoku

D.1 Introduction

D.2 Deitel Sudoku Resource Center

D.3 Solution Strategies

D.4 Programming Sudoku Puzzle Solvers

D.5 Generating New Sudoku Puzzles

D.6 Conclusion

Appendices on the Web

Appendices E through I are PDF documents posted online at the book’s Companion

Website (located at www.pearsonhighered.com/deitel).

E Game Programming with the Allegro C Library

E.1 Introduction

E.2 Installing Allegro

E.3 A Simple Allegro Program

E.4 Simple Graphics: Importing Bitmaps and Blitting

E.5 Animation with Double Buffering

E.6 Importing and Playing Sounds

E.7 Keyboard Input

E.8 Fonts and Displaying Text

E.9 Implementing the Game of Pong

E.10 Timers in Allegro

E.11 The Grabber and Allegro Datafiles

E.12 Other Allegro Capabilities

E.13 Allegro Resource Center

F Sorting: A Deeper Look

F.1 Introduction

F.2 Big O Notation

F.3 Selection Sort

F.4 Insertion Sort

F.5 Merge Sort

G Introduction to C99

G.1 Introduction

G.2 Support for

G.3 New C99

G.4 // Comments

G.5 Mixing Declarations and Executable Code

G.6 Declaring a Variable in a for Statement Header

G.7 Designated Initializers and Compound Literals

G.8 Type bool

G.9 Implicit int in Function Declarations

G.10 Complex Numbers

G.11 Variable-Length Arrays

G.12 The snprintf Function: Helping Avoid Hacker Attacks

G.13 Additions to the Preprocessor

G.14 Other C99 Features

G.15 Web Resources

H Using the Visual Studio Debugger

H.1 Introduction

H.2 Breakpoints and the Continue Command

H.3 Locals and Watch Windows

H.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands

H.5 Autos Window

H.6 Wrap-Up

I Using the GNU Debugger

I.1 Introduction

I.2 Breakpoints and the run, stop, continue and print Commands

I.3 print and set Commands

I.4 Controlling Execution Using the step, finish and next Commands

I.5 watch Command

I.6 Wrap-Up

Index

Updates

Submit Errata

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.

Overview


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.

Surveys

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.

Newsletters

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.

Security


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

Children


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

Marketing


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.

Choice/Opt-out


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.

Links


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