Home > Store

C Primer Plus, 6th Edition

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

C Primer Plus, 6th Edition

Best Value Purchase

Book + eBook Bundle

  • Your Price: $72.79
  • List Price: $117.98
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $55.99
  • List Price: $69.99
  • Usually ships in 24 hours.

eBook (Watermarked)

  • Your Price: $38.39
  • List Price: $47.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

About

Features

  • Solutions to the exercises in the text are available in the IRC.

Description

  • Copyright 2014
  • Dimensions: 7" x 9"
  • Pages: 1072
  • Edition: 6th
  • Book
  • ISBN-10: 0-321-92842-3
  • ISBN-13: 978-0-321-92842-9

C Primer Plus is a carefully tested, well-crafted, and complete tutorial on a subject core to programmers and developers. This computer science classic teaches principles of programming, including structured code and top-down design.

Author and educator Stephen Prata has created an introduction to C that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.

Review questions and programming exercises at the end of each chapter bring out the most critical pieces of information and help readers understand and digest the most difficult concepts. A friendly and easy-to-use self-study guide, this book is appropriate for serious students of programming, as well as developers proficient in other languages with a desire to better understand the fundamentals of this core language.

The sixth edition of this book has been updated and expanded to cover the latest developments in C as well as to take a detailed look at the new C11 standard. In C Primer Plus you’ll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:

  • Complete, integrated discussion of both C language fundamentals and additional features
  • Clear guidance about when and why to use different parts of the language
  • Hands-on learning with concise and simple examples that develop your understanding of a concept or two at a time
  • Hundreds of practical sample programs
  • Review questions and programming exercises at the end of each chapter to test your understanding
  • Coverage of generic C to give you the greatest flexibility

Downloads

Downloads

Download the "Examples Code" associated with C Primer Plus here

Download the "Programming Exercises Selected Answers" associated with C Primer Plus here

Sample Content

Online Sample Chapter

Data and the C Programming Language

Sample Pages

Download the sample pages (includes Chapter 3 and Index)

Table of Contents

Preface xxvii

1 Getting Ready 1

Whence C? 1

Why C? 2

Design Features 2

Efficiency 3

Portability 3

Power and Flexibility 3

Programmer Oriented 3

Shortcomings 4

Whither C? 4

What Computers Do 5

High-level Computer Languages and Compilers 6

Language Standards 7

The First ANSI/ISO C Standard 8

The C99 Standard 8

The C11 Standard 9

Using C: Seven Steps 9

Step 1: Define the Program Objectives 10

Step 2: Design the Program 10

Step 3: Write the Code 11

Step 4: Compile 11

Step 5: Run the Program 12

Step 6: Test and Debug the Program 12

Step 7: Maintain and Modify the Program 13

Commentary 13

Programming Mechanics 13

Object Code Files, Executable Files, and Libraries 14

Unix System 16

The GNU Compiler Collection and the LLVM Project 18

Linux Systems 18

Command-Line Compilers for the PC 19

Integrated Development Environments (Windows) 19

The Windows/Linux Option 21

C on the Macintosh 21

How This Book Is Organized 22

Conventions Used in This Book 22

Typeface 22

Program Output 23

Special Elements 24

Summary 24

Review Questions 25

Programming Exercise 25

2 Introducing C 27

A Simple Example of C 27

The Example Explained 28

Pass 1: Quick Synopsis 30

Pass 2: Program Details 31

The Structure of a Simple Program 40

Tips on Making Your Programs Readable 41

Taking Another Step in Using C 42

Documentation 43

Multiple Declarations 43

Multiplication 43

Printing Multiple Values 43

While You're at ItMultiple Functions 44

Introducing Debugging 46

Syntax Errors 46

Semantic Errors 47

Program State 49

Keywords and Reserved Identifiers 49

Key Concepts 50

Summary 51

Review Questions 51

Programming Exercises 53

3 Data and C 55

A Sample Program 55

What's New in This Program? 57

Data Variables and Constants 59

Data: Data-Type Keywords 59

Integer Versus Floating-Point Types 60

The Integer 61

The Floating-Point Number 61

Basic C Data Types 62

The int Type 62

Other Integer Types 66

Using Characters: Type char 71

The _Bool Type 77

Portable Types: stdint.h and inttypes.h 77

Types float, double, and long double 79

Complex and Imaginary Types 85

Beyond the Basic Types 85

Type Sizes 87

Using Data Types 88

Arguments and Pitfalls 89

One More Example: Escape Sequences 91

What Happens When the Program Runs 91

Flushing the Output 92

Key Concepts 93

Summary 93

Review Questions 94

Programming Exercises 97

4 Character Strings and Formatted Input/Output 99

Introductory Program 99

Character Strings: An Introduction 101

Type char Arrays and the Null Character 101

Using Strings 102

The strlen() Function 103

Constants and the C Preprocessor 106

The const Modifier 109

Manifest Constants on the Job 109

Exploring and Exploiting printf() and scanf() 112

The printf() Function 112

Using printf() 113

Conversion Specification Modifiers for printf() 115

What Does a Conversion Specification Convert? 122

Using scanf() 128

The * Modifier with printf() and scanf() 133

Usage Tips for printf() 135

Key Concepts 136

Summary 137

Review Questions 138

Programming Exercises 140

5 Operators, Expressions, and Statements 143

Introducing Loops 144

Fundamental Operators 146

Assignment Operator: = 146

Addition Operator: + 149

Subtraction Operator: 149

Sign Operators: and + 150

Multiplication Operator: * 151

Division Operator: / 153

Operator Precedence 154

Precedence and the Order of Evaluation 156

Some Additional Operators 157

The sizeof Operator and the size_t Type 158

Modulus Operator: % 159

Increment and Decrement Operators: ++ and -- 160

Decrementing: -- 164

Precedence 165

Don't Be Too Clever 166

Expressions and Statements 167

Expressions 167

Statements 168

Compound Statements (Blocks) 171

Type Conversions 174

The Cast Operator 176

Function with Arguments 177

A Sample Program 180

Key Concepts 182

Summary 182

Review Questions 183

Programming Exercises 187

6 C Control Statements: Looping 189

Revisiting the while Loop 190

Program Comments 191

C-Style Reading Loop 192

The while Statement 193

Terminating a while Loop 194

When a Loop Terminates 194

while: An Entry-Condition Loop 195

Syntax Points 195

Which Is Bigger: Using Relational Operators and Expressions 197

What Is Truth? 199

What Else Is True? 200

Troubles with Truth 201

The New _Bool Type 203

Precedence of Relational Operators 205

Indefinite Loops and Counting Loops 207

The for Loop 208

Using for for Flexibility 210

More Assignment Operators: +=, -=, *=, /=, %= 215

The Comma Operator 215

Zeno Meets the for Loop 218

An Exit-Condition Loop: do while 220

Which Loop? 223

Nested Loops 224

Program Discussion 225

A Nested Variation 225

Introducing Arrays 226

Using a for Loop with an Array 228

A Loop Example Using a Function Return Value 230

Program Discussion 232

Using Functions with Return Values 233

Key Concepts 234

Summary 235

Review Questions 236

Programming Exercises 241

7 C Control Statements: Branching and Jumps 245

The if Statement 246

Adding else to the if Statement 248

Another Example: Introducing getchar() and putchar() 250

The ctype.h Family of Character Functions 252

Multiple Choice else if 254

Pairing else with if 257

More Nested ifs 259

Let's Get Logical 263

Alternate Spellings: The iso646.h Header File 265

Precedence 265

Order of Evaluation 266

Ranges 267

A Word-Count Program 268

The Conditional Operator: ?: 271

Loop Aids: continue and break 274

The continue Statement 274

The break Statement 277

Multiple Choice: switch and break 280

Using the switch Statement 281

Reading Only the First Character of a Line 283

Multiple Labels 284

switch and if else 286

The goto Statement 287

Avoiding goto 287

Key Concepts 291

Summary 291

Review Questions 292

Programming Exercises 296

8 Character Input/Output and Input Validation 299

Single-Character I/O: getchar() and putchar() 300

Buffers 301

Terminating Keyboard Input 302

Files, Streams, and Keyboard Input 303

The End of File 304

Redirection and Files 307

Unix, Linux, and Windows Command Prompt Redirection 307

Creating a Friendlier User Interface 312

Working with Buffered Input 312

Mixing Numeric and Character Input 314

Input Validation 317

Analyzing the Program 322

The Input Stream and Numbers 323

Menu Browsing 324

Tasks 324

Toward a Smoother Execution 325

Mixing Character and Numeric Input 327

Key Concepts 330

Summary 331

Review Questions 331

Programming Exercises 332

9 Functions 335

Reviewing Functions 335

Creating and Using a Simple Function 337

Analyzing the Program 338

Function Arguments 340

Defining a Function with an Argument: Formal Parameters 342

Prototyping a Function with Arguments 343

Calling a Function with an Argument: Actual Arguments 343

The Black-Box Viewpoint 345

Returning a Value from a Function with return 345

Function Types 348

ANSI C Function Prototyping 349

The Problem 350

The ANSI C Solution 351

No Arguments and Unspecified Arguments 352

Hooray for Prototypes 353

Recursion 353

Recursion Revealed 354

Recursion Fundamentals 355

Tail Recursion 356

Recursion and Reversal 358

Recursion Pros and Cons 360

Compiling Programs with Two or More Source Code Files 361

Unix 362

Linux 362

DOS Command-Line Compilers 362

Windows and Apple IDE Compilers 362

Using Header Files 363

Finding Addresses: The & Operator 367

Altering Variables in the Calling Function 369

Pointers: A First Look 371

The Indirection Operator: * 371

Declaring Pointers 372

Using Pointers to Communicate Between Functions 373

Key Concepts 378

Summary 378

Review Questions 379

Programming Exercises 380

10 Arrays and Pointers 383

Arrays 383

Initialization 384

Designated Initializers (C99) 388

Assigning Array Values 390

Array Bounds 390

Specifying an Array Size 392

Multidimensional Arrays 393

Initializing a Two-Dimensional Array 397

More Dimensions 398

Pointers and Arrays 398

Functions, Arrays, and Pointers 401

Using Pointer Parameters 404

Comment: Pointers and Arrays 407

Pointer Operations 407

Protecting Array Contents 412

Using const with Formal Parameters 413

More About const 415

Pointers and Multidimensional Arrays 417

Pointers to Multidimensional Arrays 420

Pointer Compatibility 421

Functions and Multidimensional Arrays 423

Variable-Length Arrays (VLAs) 427

Compound Literals 431

Key Concepts 434

Summary 435

Review Questions 436

Programming Exercises 439

11 Character Strings and String Functions 441

Representing Strings and String I/O 441

Defining Strings Within a Program 442

Pointers and Strings 451

String Input 453

Creating Space 453

The Unfortunate gets() Function 453

The Alternatives to gets() 455

The scanf() Function 462

String Output 464

The puts() Function 464

The fputs() Function 465

The printf() Function 466

The Do-It-Yourself Option 466

String Functions 469

The strlen() Function 469

The strcat() Function 471

The strncat() Function 473

The strcmp() Function 475

The strcpy() and strncpy() Functions 482

The sprintf() Function 487

Other String Functions 489

A String Example: Sorting Strings 491

Sorting Pointers Instead of Strings 493

The Selection Sort Algorithm 494

The ctype.h Character Functions and Strings 495

Command-Line Arguments 497

Command-Line Arguments in Integrated Environments 500

Command-Line Arguments with the Macintosh 500

String-to-Number Conversions 500

Key Concepts 504

Summary 504

Review Questions 505

Programming Exercises 508

12 Storage Classes, Linkage, and Memory Management 511

Storage Classes 511

Scope 513

Linkage 515

Storage Duration 516

Automatic Variables 518

Register Variables 522

Static Variables with Block Scope 522

Static Variables with External Linkage 524

Static Variables with Internal Linkage 529

Multiple Files 530

Storage-Class Specifier Roundup 530

Storage Classes and Functions 533

Which Storage Class? 534

A Random-Number Function and a Static Variable 534

Roll 'Em 538

Allocated Memory: malloc() and free() 543

The Importance of free() 547

The calloc() Function 548

Dynamic Memory Allocation and Variable-Length Arrays 548

Storage Classes and Dynamic Memory Allocation 549

ANSI C Type Qualifiers 551

The const Type Qualifier 552

The volatile Type Qualifier 554

The restrict Type Qualifier 555

The _Atomic Type Qualifier (C11) 556

New Places for Old Keywords 557

Key Concepts 558

Summary 558

Review Questions 559

Programming Exercises 561

13 File Input/Output 565

Communicating with Files 565

What Is a File? 566

The Text Mode and the Binary Mode 566

Levels of I/O 568

Standard Files 568

Standard I/O 568

Checking for Command-Line Arguments 569

The fopen() Function 570

The getc() and putc() Functions 572

End-of-File 572

The fclose() Function 57

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