C How To Program (With Case Studies Introducing Applications and Systems Programming) (9th Edition) Paul
C How To Program (With Case Studies Introducing Applications and Systems Programming) (9th Edition) Paul
o Program (With Case Studies Introducing Applications and Systems Programming) (9th Editi
EDITION
com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-pro
C HOW TO PROGRAM
NINTH EDITION
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on the appropriate page of appearance
w to Program (With Case Studies Introducing Applications and Systems Programming) (9th Edition)
or in the Credits on pages.
The rights of Paul Deitel and Harvey Deitel to be identified as the authors of this work, have been asserted by them in accordance with the Copyright,
Designs and Patents Act 1988.
Authorized adaptation from the United States edition, entitled C How to Program, 9th Edition, ISBN 978-0-13-739839-3 by Paul Deitel and Harvey Deitel
published by Pearson Education © 2022.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic,
mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a license permitting restricted copying in
the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.
All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any
trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners.
For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights and Permissions
department, please visit www.pearsoned.com/permissions/.
This eBook is a standalone product and may or may not include all assets that were part of the print version. It also does not provide access
to other Pearson digital products like MyLab and Mastering. The publisher reserves the right to remove any material in this eBook at any
time.
1 22
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
Trademarks
Apple, Xcode, Swift, Objective-C, iOS and macOS are trademarks or registered
trademarks of Apple, Inc.
Java is a registered trademark of Oracle and/or its affiliates.
Linux is a registered trademark of Linus Torvalds.
Microsoft and/or its respective suppliers make no representations about the suit-
ability of the information contained in the documents and related graphics published
as part of the services for any purpose. All such documents and related graphics are
provided “as is” without warranty of any kind. Microsoft and/or its respective sup-
pliers hereby disclaim all warranties and conditions with regard to this information,
including all warranties and conditions of merchantability, whether express, implied
or statutory, fitness for a particular purpose, title and non-infringement. In no event
shall Microsoft and/or its respective suppliers be liable for any special, indirect or con-
sequential damages or any damages whatsoever resulting from loss of use, data or
profits, whether in an action of contract, negligence or other tortious action, arising
out of or in connection with the use or performance of information available from
the services.
The documents and related graphics contained herein could include technical inac-
curacies or typographical errors. Changes are periodically added to the information
herein. Microsoft and/or its respective suppliers may make improvements and/or
changes in the product(s) and/or the program(s) described herein at any time. Partial
screen shots may be viewed in full within the software version specified.
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
Contents
Appendices E–H are PDF documents posted online at the book’s Companion
Website (located at https://www.pearsonglobaleditions.com).
Preface 17
6 Contents
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
1.10.3 Compiling and Running a C Application with GNU gcc
on Linux 84
1.10.4 Compiling and Running a C Application in a GCC Docker
Container Running Natively over Windows 10, macOS
or Linux 86
1.11 Internet, World Wide Web, the Cloud and IoT 87
1.11.1 The Internet: A Network of Networks 88
1.11.2 The World Wide Web: Making the Internet User-Friendly 89
1.11.3 The Cloud 89
1.11.4 The Internet of Things 90
1.12 Software Technologies 91
1.13 How Big Is Big Data? 91
1.13.1 Big-Data Analytics 97
1.13.2 Data Science and Big Data Are Making a Difference: Use Cases 98
1.14 Case Study—A Big-Data Mobile Application 99
1.15 AI—at the Intersection of Computer Science and Data Science 100
Contents 7
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
4 Program Control 185
4.1 Introduction 186
4.2 Iteration Essentials 186
4.3 Counter-Controlled Iteration 187
4.4 for Iteration Statement 188
4.5 Examples Using the for Statement 192
4.6 switch Multiple-Selection Statement 196
4.7 do…while Iteration Statement 202
4.8 break and continue Statements 203
4.9 Logical Operators 205
4.10 Confusing Equality (==) and Assignment (=) Operators 209
4.11 Structured-Programming Summary 210
4.12 Secure C Programming 215
5 Functions 231
5.1 Introduction 232
5.2 Modularizing Programs in C 232
5.3 Math Library Functions 234
5.4 Functions 235
5.5 Function Definitions 236
5.5.1 square Function 236
5.5.2 maximum Function 239
5.6 Function Prototypes: A Deeper Look 240
5.7 Function-Call Stack and Stack Frames 243
5.8 Headers 247
5.9 Passing Arguments by Value and by Reference 249
5.10 Random-Number Generation 249
5.11 Game Simulation Case Study: Rock, Paper, Scissors 254
5.12 Storage Classes 260
5.13 Scope Rules 262
5.14 Recursion 265
5.15 Example Using Recursion: Fibonacci Series 269
5.16 Recursion vs. Iteration 272
5.17 Secure C Programming—Secure Random-Number Generation 275
Random-Number Simulation Case Study: The Tortoise and the Hare 294
6 Arrays 297
6.1 Introduction 298
6.2 Arrays 298
6.3 Defining Arrays 300
6.4 Array Examples 300
DEIT8393_09_GE_Final.book Page 8 Tuesday, April 12, 2022 3:20 PM
8 Contents
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
6.4.1 Defining an Array and Using a Loop to Set the Array’s
Element Values 301
6.4.2 Initializing an Array in a Definition with an Initializer List 302
6.4.3 Specifying an Array’s Size with a Symbolic Constant and
Initializing Array Elements with Calculations 303
6.4.4 Summing the Elements of an Array 304
6.4.5 Using Arrays to Summarize Survey Results 304
6.4.6 Graphing Array Element Values with Bar Charts 306
6.4.7 Rolling a Die 60,000,000 Times and Summarizing
the Results in an Array 307
6.5 Using Character Arrays to Store and Manipulate Strings 309
6.5.1 Initializing a Character Array with a String 309
6.5.2 Initializing a Character Array with an Initializer List
of Characters 309
6.5.3 Accessing the Characters in a String 309
6.5.4 Inputting into a Character Array 309
6.5.5 Outputting a Character Array That Represents a String 310
6.5.6 Demonstrating Character Arrays 310
6.6 Static Local Arrays and Automatic Local Arrays 312
6.7 Passing Arrays to Functions 314
6.8 Sorting Arrays 318
6.9 Intro to Data Science Case Study: Survey Data Analysis 321
6.10 Searching Arrays 326
6.10.1 Searching an Array with Linear Search 326
6.10.2 Searching an Array with Binary Search 328
6.11 Multidimensional Arrays 332
6.11.1 Illustrating a Two-Dimensional Array 332
6.11.2 Initializing a Double-Subscripted Array 333
6.11.3 Setting the Elements in One Row 335
6.11.4 Totaling the Elements in a Two-Dimensional Array 335
6.11.5 Two-Dimensional Array Manipulations 335
6.12 Variable-Length Arrays 339
6.13 Secure C Programming 343
7 Pointers 363
7.1 Introduction 364
7.2 Pointer Variable Definitions and Initialization 365
7.3 Pointer Operators 366
7.4 Passing Arguments to Functions by Reference 369
7.5 Using the const Qualifier with Pointers 373
7.5.1 Converting a String to Uppercase Using a Non-Constant
Pointer to Non-Constant Data 374
F02_DEIT8393_09_GE_TOC_final.fm Page 9 Wednesday, April 27, 2022 10:06 AM
Contents 9
w.yakibooki.com/download/c-how-to-program-with-case-studies-introducing-applications-and-systems-programming-9
7.5.2 Printing a String One Character at a Time Using a
Non-Constant Pointer to Constant Data 374
7.5.3 Attempting to Modify a Constant Pointer to
Non-Constant Data 376
7.5.4 Attempting to Modify a Constant Pointer to Constant Data 377
7.6 Bubble Sort Using Pass-By-Reference 378
7.7 sizeof Operator 382
7.8 Pointer Expressions and Pointer Arithmetic 384
7.8.1 Pointer Arithmetic Operators 385
7.8.2 Aiming a Pointer at an Array 385
7.8.3 Adding an Integer to a Pointer 385
7.8.4 Subtracting an Integer from a Pointer 386
7.8.5 Incrementing and Decrementing a Pointer 386
7.8.6 Subtracting One Pointer from Another 386
7.8.7 Assigning Pointers to One Another 386
7.8.8 Pointer to void 386
7.8.9 Comparing Pointers 387
7.9 Relationship between Pointers and Arrays 387
7.9.1 Pointer/Offset Notation 387
7.9.2 Pointer/Subscript Notation 388
7.9.3 Cannot Modify an Array Name with Pointer Arithmetic 388
7.9.4 Demonstrating Pointer Subscripting and Offsets 388
7.9.5 String Copying with Arrays and Pointers 390
7.10 Arrays of Pointers 392
7.11 Random-Number Simulation Case Study: Card Shuffling and Dealing 393
7.12 Function Pointers 398
7.12.1 Sorting in Ascending or Descending Order 398
7.12.2 Using Function Pointers to Create a Menu-Driven System 401
7.13 Secure C Programming 403
Special Section: Building Your Own Computer as a Virtual Machine 417
Special Section—Embedded Systems Programming Case Study:
Robotics with the Webots Simulator 424