基本信息
源码名称:C Primer Plus, Fifth Edition.pdf
源码大小:5.37M
文件格式:.pdf
开发语言:C/C++
更新时间:2020-08-13
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C语言学习手册(英文原版),编程,从阅读英文原版开启
C primer 5th Edition.pdf
【文件目录】
Table of content Chapter 1. Getting Ready................................................................................................................ 1 Whence C? ............................................................................................................................... 1 Why C?...................................................................................................................................... 1 Whither C? ................................................................................................................................ 3 What Computers Do................................................................................................................. 4 High-level Computer Languages and Compilers .................................................................. 5 Using C: Seven Steps.............................................................................................................. 6 Programming Mechanics......................................................................................................... 9 Language Standards.............................................................................................................. 15 How This Book Is Organized................................................................................................. 16 Conventions Used in This Book............................................................................................ 16 Summary ................................................................................................................................. 18 Review Questions .................................................................................................................. 18 Programming Exercise........................................................................................................... 19 Chapter 2. Introducing C ............................................................................................................... 19 A Simple Example of C.......................................................................................................... 19 The Example Explained......................................................................................................... 20 The Structure of a Simple Program...................................................................................... 30 Tips on Making Your Programs Readable........................................................................... 31 Taking Another Step in Using C............................................................................................ 32 While You're at It—Multiple Functions ................................................................................. 33 Introducing Debugging........................................................................................................... 35 Keywords and Reserved Identifiers...................................................................................... 38 Key Concepts.......................................................................................................................... 38 Summary ................................................................................................................................. 39 Review Questions .................................................................................................................. 39 Programming Exercises......................................................................................................... 40 Chapter 3. Data and C................................................................................................................... 41 A Sample Program................................................................................................................. 42 Data Variables and Constants .............................................................................................. 44 Data: Data-Type Keywords ................................................................................................... 44 Basic C Data Types ............................................................................................................... 47 Using Data Types................................................................................................................... 70 Arguments and Pitfalls........................................................................................................... 70 One More Example: Escape Sequences ............................................................................. 72 Key Concepts.......................................................................................................................... 74 Summary ................................................................................................................................. 74 Review Questions .................................................................................................................. 75 Programming Exercises......................................................................................................... 77 Chapter 4. Character Strings and Formatted Input/Output........................................................ 77 Introductory Program ............................................................................................................. 78 Character Strings: An Introduction........................................................................................ 79 Constants and the C Preprocessor ...................................................................................... 83 Exploring and Exploiting printf() and scanf()............................................................ 88 Key Concepts........................................................................................................................ 108 Summary ............................................................................................................................... 109 Review Questions ................................................................................................................ 110 Programming Exercises....................................................................................................... 112 Chapter 5. Operators, Expressions, and Statements ............................................................... 113 Introducing Loops................................................................................................................. 113 Fundamental Operators....................................................................................................... 115 Some Additional Operators ................................................................................................. 124 Expressions and Statements............................................................................................... 132 Type Conversions ................................................................................................................ 138 Function with Arguments ..................................................................................................... 141 A Sample Program............................................................................................................... 142 Key Concepts........................................................................................................................ 144 Summary ............................................................................................................................... 144 Review Questions ................................................................................................................ 145 Programming Exercises....................................................................................................... 147 Chapter 6. C Control Statements: Looping................................................................................ 149 Revisiting the while Loop .................................................................................................. 150 The while Statement.......................................................................................................... 152 Which Is Bigger: Using Relational Operators and Expressions....................................... 156 Indefinite Loops and Counting Loops................................................................................. 164 The for Loop ....................................................................................................................... 165 More Assignment Operators: =, -=, *=, /=, %=.............................................................. 171 The Comma Operator.......................................................................................................... 171 An Exit-Condition Loop: do while.................................................................................... 176 Which Loop?......................................................................................................................... 179 Nested Loops........................................................................................................................ 180 Introducing Arrays ................................................................................................................ 181 A Loop Example Using a Function Return Value.............................................................. 184 Key Concepts........................................................................................................................ 188 Summary ............................................................................................................................... 188 Review Questions ................................................................................................................ 189 Programming Exercises....................................................................................................... 193 Chapter 7. C Control Statements: Branching and Jumps ........................................................ 195 The if Statement................................................................................................................. 196 Adding else to the if Statement ...................................................................................... 197 Let's Get Logical................................................................................................................... 211 A Word-Count Program ....................................................................................................... 216 The Conditional Operator: ?:.............................................................................................. 219 Loop Aids: continue and break...................................................................................... 221 Multiple Choice: switch and break................................................................................. 225 The goto Statement............................................................................................................ 232 Key Concepts........................................................................................................................ 235 Summary ............................................................................................................................... 236 Review Questions ................................................................................................................ 236 Programming Exercises....................................................................................................... 239 Chapter 8. Character Input/Output and Input Validation.......................................................... 241 Single-Character I/O: getchar() and putchar() ........................................................ 241 Buffers ................................................................................................................................... 242 Terminating Keyboard Input................................................................................................ 243 Redirection and Files ........................................................................................................... 247 Creating a Friendlier User Interface ................................................................................... 251 Input Validation..................................................................................................................... 256 Menu Browsing..................................................................................................................... 261 Key Concepts........................................................................................................................ 266 Summary ............................................................................................................................... 266 Review Questions ................................................................................................................ 266 Programming Exercises....................................................................................................... 267 Chapter 9. Functions ................................................................................................................... 269 Reviewing Functions............................................................................................................ 269 ANSI C Function Prototyping .............................................................................................. 281 Recursion .............................................................................................................................. 285 Compiling Programs with Two or More Source Code Files ............................................. 291 Finding Addresses: The & Operator ................................................................................... 295 Altering Variables in the Calling Function .......................................................................... 296 Pointers: A First Look........................................................................................................... 298 Key Concepts........................................................................................................................ 305 Summary ............................................................................................................................... 305 Review Questions ................................................................................................................ 305 Programming Exercises....................................................................................................... 307 Chapter 10. Arrays and Pointers ................................................................................................ 307 Arrays .................................................................................................................................... 308 Multidimensional Arrays....................................................................................................... 316 Pointers and Arrays.............................................................................................................. 320 Functions, Arrays, and Pointers.......................................................................................... 323 Pointer Operations ............................................................................................................... 328 Protecting Array Contents ................................................................................................... 332 Pointers and Multidimensional Arrays................................................................................ 336 Variable-Length Arrays (VLAs) ........................................................................................... 344 Compound Literals ............................................................................................................... 347 Key Concepts........................................................................................................................ 349 Summary ............................................................................................................................... 350 Review Questions ................................................................................................................ 351 Programming Exercises....................................................................................................... 353 Chapter 11. Character Strings and String Functions................................................................ 355 Representing Strings and String I/O................................................................................... 355 String Input............................................................................................................................ 364 String Output......................................................................................................................... 369 The Do-It-Yourself Option.................................................................................................... 372 String Functions.................................................................................................................... 374 A String Example: Sorting Strings ...................................................................................... 389 The ctype.h Character Functions and Strings ............................................................... 392 Command-Line Arguments.................................................................................................. 393 String-to-Number Conversions............................................................................................ 396 Key Concepts........................................................................................................................ 399 Summary ............................................................................................................................... 399 Review Questions ................................................................................................................ 399 Programming Exercises....................................................................................................... 402 Chapter 12. Storage Classes, Linkage, and Memory Management ....................................... 404 Storage Classes ................................................................................................................... 404 Storage-Class Specifiers ..................................................................................................... 418 Storage Classes and Functions.......................................................................................... 420 A Random-Number Function and a Static Variable.......................................................... 421 Roll 'Em ................................................................................................................................. 424 Allocated Memory: malloc() and free()...................................................................... 428 ANSI C Type Qualifiers........................................................................................................ 433 Key Concepts........................................................................................................................ 439 Summary ............................................................................................................................... 439 Review Questions ................................................................................................................ 440 Programming Exercises....................................................................................................... 442 Chapter 13. File Input/Output...................................................................................................... 444 Communicating with Files.................................................................................................... 444 Standard I/O.......................................................................................................................... 446 A Simple-Minded File-Condensing Program ..................................................................... 451 File I/O: fprintf(), fscanf(), fgets(), and fputs()............................................ 453 Adventures in Random Access: fseek() and ftell()................................................ 456 Behind the Scenes with Standard I/O ................................................................................ 460 Other Standard I/O Functions ............................................................................................. 461 Key Concepts........................................................................................................................ 468 Summary ............................................................................................................................... 469 Review Questions ................................................................................................................ 470 Programming Exercises....................................................................................................... 471 Chapter 14. Structures and Other Data Forms ......................................................................... 473 Sample Problem: Creating an Inventory of Books ............................................................ 474 Setting Up the Structure Declaration.................................................................................. 475 Defining a Structure Variable .............................................................................................. 476 Arrays of Structures ............................................................................................................. 479 Nested Structures................................................................................................................. 483 Pointers to Structures .......................................................................................................... 485 Telling Functions About Structures..................................................................................... 487 Saving the Structure Contents in a File.............................................................................. 502 Structures: What Next?........................................................................................................ 506 Unions: A Quick Look .......................................................................................................... 506 Enumerated Types............................................................................................................... 509 typedef: A Quick Look ...................................................................................................... 513 Fancy Declarations............................................................................................................... 515 Functions and Pointers ........................................................................................................ 517 Key Concepts........................................................................................................................ 523 Summary ............................................................................................................................... 523 Review Questions ................................................................................................................ 524 Programming Exercises....................................................................................................... 526 Chapter 15. Bit Fiddling............................................................................................................... 529 Binary Numbers, Bits, and Bytes ........................................................................................ 530 Other Number Bases ........................................................................................................... 532 C's Bitwise Operators........................................................................................................... 534 Bit Fields................................................................................................................................ 543 Key Concepts........................................................................................................................ 554 Summary ............................................................................................................................... 554 Review Questions ................................................................................................................ 554 Programming Exercises....................................................................................................... 556 Chapter 16. The C Preprocessor and the C Library ................................................................. 558 First Steps in Translating a Program.................................................................................. 558 Manifest Constants: #define ............................................................................................ 559 Using Arguments with #define......................................................................................... 564 Macro or Function? .............................................................................................................. 570 File Inclusion: #include .................................................................................................... 571 Other Directives.................................................................................................................... 575 Inline Functions..................................................................................................................... 583 The C Library ........................................................................................................................ 585 The Math Library .................................................................................................................. 587 The General Utilities Library................................................................................................ 589 The Assert Library ................................................................................................................ 596 memcpy() and memmove() from the string.h Library ................................................ 597 Variable Arguments: stdarg.h......................................................................................... 599 Key Concepts........................................................................................................................ 601 Summary ............................................................................................................................... 601 Review Questions ................................................................................................................ 601 Programming Exercises....................................................................................................... 603 Chapter 17. Advanced Data Representation............................................................................. 605 Exploring Data Representation ........................................................................................... 606 Beyond the Array to the Linked List.................................................................................... 608 Abstract Data Types (ADTs) ............................................................................................... 615 Getting Queued with an ADT .............................................................................................. 629 Simulating with a Queue...................................................................................................... 641 The Linked List Versus the Array........................................................................................ 645 Binary Search Trees ............................................................................................................ 649 Other Directions.................................................................................................................... 671 Key Concepts........................................................................................................................ 671 Summary ............................................................................................................................... 672 Review Questions ................................................................................................................ 672 Programming Exercises....................................................................................................... 673 Appendix A. Answers to the Review Quesions......................................................................... 674 Answers to Review Questions for Chapter 1..................................................................... 674 Answers to Review Questions for Chapter 2..................................................................... 675 Answers to Review Questions for Chapter 3..................................................................... 677 Answers to Review Questions for Chapter 4..................................................................... 679 Answers to Review Questions for Chapter 5..................................................................... 682 Answers to Review Questions for Chapter 6..................................................................... 685 Answers to Review Questions for Chapter 7..................................................................... 688 Answers to Review Questions for Chapter 8..................................................................... 692 Answers to Review Questions for Chapter 9..................................................................... 693 Answers to Review Questions for Chapter 10................................................................... 695 Answers to Review Questions for Chapter 11................................................................... 698 Answers to Review Questions for Chapter 12................................................................... 701 Answers to Review Questions for Chapter 13................................................................... 702 Answers to Review Questions for Chapter 14................................................................... 705 Answers to Review Questions for Chapter 15................................................................... 708 Answers to Review Questions for Chapter 16................................................................... 709 Answers to Review Questions for Chapter 17................................................................... 711 Appendix B. Reference Section.................................................................................................. 715 Section I: Additional Reading .............................................................................................. 715 Section II: C Operators ........................................................................................................ 718 Section III: Basic Types and Storage Classes................................................................... 724 Section IV: Expressions, Statements, and Program Flow................................................ 729 Section V: The Standard ANSI C Library with C99 Additions.......................................... 735 Section VI: Extended Integer Types................................................................................... 776 Section VII: Expanded Character Support......................................................................... 779 Section VIII: C99 Numeric Computational Enhancements............................................... 784 Section IX: Differences Between C and C ....................................................................