1. 首页
  2. 课程学习
  3. C++/C
  4. C Primer Plus, Fifth Edition.pdf

C Primer Plus, Fifth Edition.pdf

上传者: 2022-07-12 02:41:36上传 .PDF文件 5.37 MB 热度 11次

C语言学习手册(英文原版),编程,从阅读英文原版开启

C primer 5th Edition.pdf

【文件目录】

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

下载地址
用户评论