实例介绍
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 ....................................................................
标签: C Primer plus Primer plus edit fi
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论