Contents
Part 1 Fundamentals1
Chapter 1 Introduction to Computer Programming1
1.1 History and Hardware1
1.2 Programming Languages7
1.3 Algorithms12
1.4 The Software Development Process15
1.5 Case Study: Design and Development22
1.6 Common Programming Errors25
1.7 Chapter Summary25
1.8 Chapter Appendix: Numerical Storage Codes26
Chapter 2 Getting Started in C Programming28
2.1 Introduction to C Programming28
2.2 Programming Style36
2.3 Data Types40
2.4 Arithmetic Operations45
2.5 Variables and Declarations53
2.6 Case Study: Temperature Conversion61
2.7 Common Programming and Compiler Errors64
2.8 Chapter Summary66
2.9 Chapter Supplement: Memory Allocation67
Chapter 3 Processing and Interactive Input73
3.1 Assignment73
3.2 Mathematical Library Functions81
3.3 Interactive Input85
3.4 Formatted Output94
3.5 Symbolic Constants101
3.6 Case Study: Interactive Input103
3.7 Common Programming and Compiler Errors108
3.8 Chapter Summary109
3.9 Chapter Supplement: Introduction to Abstraction110
Part 2 Flow of Control112
Chapter 4 Selection112
4.1 Relational Expressions112
4.2 The if and if-else Statements117
4.3 The if-else Chain126
4.4 The switch Statement132
4.5 Case Study: Data Validation138
4.6 Common Programming and Compiler Errors141
4.7 Chapter Summary143
4.8 Chapter Supplement: Errors, Testing, and Debugging144
Chapter 5 Repetition149
5.1 Basic Loop Structures149
5.2 The while Statement152
5.3 Computing Sums and Averages Using a while Loop158
5.4 The for Statement167
5.5 Case Studies: Loop Programming Techniques174
5.6 Nested Loops180
5.7 The do-while Statement183
5.8 Common Programming and Compiler Errors187
5.9 Chapter Summary188
Chapter 6 Modularity Using Functions: Part I190
6.1 Function and Parameter Declarations190
6.2 Returning a Value201
6.3 Case Study: Calculating Age Norms209
6.4 Standard Library Functions217
6.5 Common Programming and Compiler Errors228
6.6 Chapter Summary229
Chapter 7 Modularity Using Functions: Part II230
7.1 Variable Scope231
7.2 Variable Storage Class236
7.3 Pass by Reference242
7.4 Case Study: Swapping Values251
7.5 Recursion257
7.6 Common Programming and Compiler Errors261
7.7 Chapter Summary262
Part 3 Completing the Basics264
Chapter 8 Arrays264
8.1 One-Dimensional Arrays265
8.2?Array Initialization272
8.3 Arrays as Function Arguments276
8.4 Case Study: Computing Averages and Standard Deviations279
8.5 Two-Dimensional Arrays284
8.6 Common Programming and Compiler Errors292
8.7 Chapter Summary293
8.8 Chapter Supplement: Searching and Sorting Methods293
Chapter 9 Character Strings312
9.1 String Fundamentals312
9.2 Library Functions321
9.3 Input Data Validation327
9.4 Formatting Strings (Optional)333
9.5 Case Study: Character and Word Counting335
9.6 Common Programming and Compiler Errors340
9.7 Chapter Summary341
Chapter 10 Data Files342
10.1?Declaring, Opening, and Closing File Streams342
10.2?Reading from and Writing to Text Files352
10.3?Random File Access359
10.4?Passing and Returning Filenames361
10.5?Case Study: Creating and Using a Table of Constants363
10.6?Writing and Reading Binary Files (Optional)371
10.7?Common Programming and Compiler Errors375
10.8?Chapter Summary376
10.9?Chapter Supplement: Control Codes377
Part 4 Additional Topics380
Chapter 11 Arrays, Addresses, and Pointers380
11.1?Array Names as Pointers380
11.2?Manipulating Pointers385
11.3?Passing and Using Array Addresses390
11.4?Processing Strings Using Pointers395
11.5?Creating Strings Using Pointers399
11.6?Common Programming and Compiler Errors404
11.7?Chapter Summary405
Chapter 12 Structures406
12.1?Single Structures406
12.2?Arrays of Structures411
12.3?Passing and Returning Structures415
12.4?Unions420
12.5?Common Programming and Compiler Errors422
12.6?Chapter Summary423
Chapter 13 Dynamic Data Structures425
13.1?Introduction to Linked Lists425
13.2?Dynamic Memory Allocation432
13.3?Stacks436
13.4?Queues442
13.5?Dynamically Linked Lists447
13.6?Common Programming and Compiler Errors453
13.7?Chapter Summary454
Chapter 14 Additional Capabilities456
14.1?Additional Features456
14.2?Bit Operations461
14.3?Macros467
14.4?Command-Line Arguments469
14.5?Common Programming and Compiler Errors473
14.6?Chapter Summary473
Chapter 15 A Brief Introduction to C 475
15.1?Procedural Programming in C 475
15.2?Object-Oriented C 479
15.3?Common Programming and Compiler Errors481
15.4?Chapter Summary482
Appendix A Operator Precedence Table484
Appendix B ASCII Character Codes485
Appendix C The Standard C Library488
Appendix D Input, Output, and Standard Error Redirection493
Appendix E Floating-Point Number Storage495
Appendix F Creating a Personal Library497
Appendix G Solutions to Short Answer Questions499