HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® 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.
The professional programmer’s Deitel® guide to procedural programming in C through 130 working code examples
Written for programmers with a background in high-level language programming, this book applies the Deitel signature live-code approach to teaching the C language and the C Standard Library. The book presents the concepts in the context of fully tested programs, complete with syntax shading, code highlighting, code walkthroughs and program outputs. The book features approximately 5,000 lines of proven C code and hundreds of savvy tips that will help you build robust applications.
Start with an introduction to C, then rapidly move on to more advanced topics, including building custom data structures, the Standard Library, select features of the new C11 standard such as multithreading to help you write high-performance applications for today’s multicore systems, and secure C programming sections that show you how to write software that is more robust and less vulnerable. You’ll enjoy the Deitels’ classic treatment of procedural programming. When you’re finished, you’ll have everything you need to start building industrial-strength C applications.
Practical, example-rich coverage of:
Visit www.deitel.com
Preface xv
Chapter 1: Introduction 1
1.1 Introduction 2
1.2 The C Programming Language 2
1.3 CStandard Library 4
1.4 C++ and Other C-Based Languages 4
1.5 Typical C Program Development Environment 5
1.6 Test-Driving a C Application in Windows, Linux and Mac OS X 8
1.7 Operating Systems 16
Chapter 2: Introduction to C Programming 19
2.1 Introduction 20
2.2 ASimple C Program: Printing a Line of Text 20
2.3 Another Simple C Program: Adding Two Integers 24
2.4 Arithmetic in C 27
2.5 Decision Making: Equality and Relational Operators 31
2.6 Secure C Programming 35
Chapter 3: Control Statements: Part I 37
3.1 Introduction 38
3.2 Control Structures 38
3.3 The if Selection Statement 40
3.4 The if…else Selection Statement 40
3.5 The while Repetition Statement 43
3.6 Class Average with Counter-Controlled Repetition 44
3.7 Class Average with Sentinel-Controlled Repetition 46
3.8 Nested Control Statements 49
3.9 Assignment Operators 51
3.10 Increment and Decrement Operators 52
3.11 Secure C Programming 55
Chapter 4: Control Statements: Part II 57
4.1 Introduction 58
4.2 Repetition Essentials 58
4.3 Counter-Controlled Repetition 59
4.4 for Repetition Statement 60
4.5 for Statement: Notes and Observations 63
4.6 Examples Using the for Statement 64
4.7 switch Multiple-Selection Statement 67
4.8 do…while Repetition Statement 73
4.9 break and continue Statements 75
4.10 Logical Operators 77
4.11 Confusing Equality (==) and Assignment (=) Operators 80
4.12 Secure C Programming 81
Chapter 5: Functions 83
5.1 Introduction 84
5.2 Program Modules in C 84
5.3 Math Library Functions 85
5.4 Functions 86
5.5 Function Definitions 87
5.6 Function Prototypes: A Deeper Look 91
5.7 Function Call Stack and Stack Frames 94
5.8 Headers 97
5.9 Passing Arguments By Value and By Reference 98
5.10 Random Number Generation 99
5.11 Example: A Game of Chance 104
5.12 Storage Classes 107
5.13 Scope Rules 109
5.14 Recursion 112
5.15 Example Using Recursion: Fibonacci Series 116
5.16 Recursion vs. Iteration 119
5.17 Secure C Programming 121
Chapter 6: Arrays 122
6.1 Introduction 123
6.2 Arrays 123
6.3 Defining Arrays 124
6.4 Array Examples 125
6.5 Passing Arrays to Functions 138
6.6 Sorting Arrays 142
6.7 Case Study: Computing Mean, Median and Mode Using Arrays 144
6.8 Searching Arrays 149
6.9 Multidimensional Arrays 155
6.10 Variable-Length Arrays 162
6.11 Secure C Programming 165
Chapter 7: Pointers 167
7.1 Introduction 168
7.2 Pointer Variable Definitions and Initialization 168
7.3 Pointer Operators 169
7.4 Passing Arguments to Functions by Reference 172
7.5 Using the const Qualifier with Pointers 176
7.6 Bubble Sort Using Pass-by-Reference 182
7.7 sizeof Operator 185
7.8 Pointer Expressions and Pointer Arithmetic 188
7.9 Relationship between Pointers and Arrays 190
7.10 Arrays of Pointers 194
7.11 Case Study: Card Shuffling and Dealing Simulation 195
7.12 Pointers to Functions 199
7.13 Secure C Programming 204
Chapter 8: Characters and Strings 205
8.1 Introduction 206
8.2 Fundamentals of Strings and Characters 206
8.3 Character-Handling Library 208
8.4 String-Conversion Functions 213
8.5 Standard Input/Output Library Functions 217
8.6 String-Manipulation Functions of the String-Handling Library 221
8.7 Comparison Functions of the String-Handling Library 224
8.8 Search Functions of the String-Handling Library 225
8.9 Memory Functions of the String-Handling Library 231
8.10 Other Functions of the String-Handling Library 236
8.11 Secure C Programming 237
Chapter 9: Formatted Input/Output 238
9.1 Introduction 239
9.2 Streams 239
9.3 Formatting Output with printf 239
9.4 Printing Integers 240
9.5 Printing Floating-Point Numbers 241
9.6 Printing Strings and Characters 243
9.7 Other Conversion Specifiers 244
9.8 Printing with Field Widths and Precision 245
9.9 Using Flags in the printf Format Control String 247
9.10 Printing Literals and Escape Sequences 250
9.11 Reading Formatted Input with scanf 251
9.12 Secure C Programming 257
Chapter 10: Structures, Unions, Bit Manipulation and Enumerations 258
10.1 Introduction 259
10.2 Structure Definitions 259
10.3 Initializing Structures 262
10.4 Accessing Structure Members 262
10.5 Using Structures with Functions 264
10.6 typedef 264
10.7 Example: High-Performance Card Shuffling and Dealing Simulation 265
10.8 Unions 268
10.9 Bitwise Operators 270
10.10 Bit Fields 279
10.11 Enumeration Constants 282
10.12 Secure C Programming 284
Chapter 11: File Processing 285
11.1 Introduction 286
11.2 Files and Streams 286
11.3 Creating a Sequential-Access File 287
11.4 Reading Data from a Sequential-Access File 292
11.5 Random-Access Files 296
11.6 Creating a Random-Access File 297
11.7 Writing Data Randomly to a Random-Access File 299
11.8 Reading Data from a Random-Access File 302
11.9 Case Study: Transaction-Processing Program 303
11.10 Secure C Programming 309
Chapter 12: Data Structures 311
12.1 Introduction 312
12.2 Self-Referential Structures 312
12.3 Dynamic Memory Allocation 313
12.4 Linked Lists 314
12.5 Stacks 323
12.6 Queues 329
12.7 Trees 335
12.8 Secure C Programming 340
Chapter 13: Preprocessor 342
13.1 Introduction 343
13.2 #include Preprocessor Directive 343
13.3 #define Preprocessor Directive: Symbolic Constants 344
13.4 #define Preprocessor Directive: Macros 344
13.5 Conditional Compilation 346
13.6 #error and #pragma Preprocessor Directives 347
13.7 # and ## Operators 348
13.8 Line Numbers 348
13.9 Predefined Symbolic Constants 348
13.10 Assertions 349
13.11 Secure C Programming 349
Chapter 14: Other Topics 351
14.1 Introduction 352
14.2 Redirecting I/O 352
14.3 Variable-Length Argument Lists 353
14.4 Using Command-Line Arguments 355
14.5 Notes on Compiling Multiple-Source-File Programs 356
14.6 Program Termination with exit and atexit 358
14.7 Suffixes for Integer and Floating-Point Literals 359
14.8 Signal Handling 360
14.9 Dynamic Memory Allocation: Functions calloc and realloc 362
14.10 Unconditional Branching with goto 363
Appendix A: Operator Precedence Chart 365
Appendix B: ASCII Character Set 367
Appendix C: Number Systems 368
C.1 Introduction 369
C.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers 372
C.3 Converting Octal and Hexadecimal Numbers to Binary Numbers 373
C.4 Converting from Binary, Octal or Hexadecimal to Decimal 373
C.5 Converting from Decimal to Binary, Octal or Hexadecimal 374
C.6 Negative Binary Numbers: Two’s Complement Notation 376
Appendix D: Sorting: A Deeper Look 378
D.1 Introduction 379
D.2 Big O Notation 379
D.3 Selection Sort 380
D.4 Insertion Sort 384
D.5 Merge Sort 387
Appendix E: Additional Features of the C Standard 394
E.1 Introduction 395
E.2 Support for C99 396
E.3 C99 Headers 396
E.4 Mixing Declarations and Executable Code 397
E.5 Declaring a Variable in a for Statement Header 397
E.6 Designated Initializers and Compound Literals 398
E.7 Type bool 401
E.8 Implicit int in Function Declarations 402
E.9 Complex Numbers 403
E.10 Variable-Length Arrays 404
E.11 Additions to the Preprocessor 407
E.12 Other C99 Features 408
E.13 New Features in the C11 Standard 411
E.14 Web Resources 422
Appendix F: Using the Visual Studio Debugger 425
F.1 Introduction 426
F.2 Breakpoints and the Continue Command 426
F.3 Locals and Watch Windows 430
F.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands 432
F.5 Autos Window 434
Appendix G: Using the GNU Debugger 436
G.1 Introduction 437
G.2 Breakpoints and the run, stop, continue and print Commands 437
G.3 print and set Commands 442
G.4 Controlling Execution Using the step, finish and next Commands 444
G.5 watch Command 446
Index 449