《C和指针 英文版》PDF下载

  • 购买积分:18 如何计算积分?
  • 作  者:(美)KennethReek著
  • 出 版 社:北京:人民邮电出版社
  • 出版年份:2013
  • ISBN:9787115308498
  • 页数:618 页
图书介绍:本书覆盖了数据、语句、操作符和表达式、指针、函数、数组、字符串、结构和联合等几乎所有重要的C编程话题,通过对指针的基础知识和高级特性的探讨,帮助程序员把指针的强大功能融入到自己的程序中去。本书是作者9年的编程及教学的经验积累。

Chapter 1:A Quick Start 1

1.1 Introduction 1

1.1.1 Spacing and Comments 5

1.1.2 Preprocessor Directives 6

1.1.3 The Main Function 8

1.1.4 The read_column_numbers Function 11

1.1.5 The rearrange Function 17

1.2 Other Capabilities 20

1.3 Compiling 21

1.4 Summary 21

1.5 Summary of Cautions 22

1.6 Summary of Programming Tips 22

1.7 Questions 23

1.8 Programming Exercises 23

Chapter 2:Basic Concepts 25

2.1 Environments 25

2.1.1 Translation 25

2.1.2 Execution 28

2.2 Lexical Rules 29

2.2.1 Characters 29

2.2.2 Comments 31

2.2.3 Free Form Source Code 32

2.2.4 Identifiers 32

2.2.5 Form of a Program 33

2.3 Program Style 33

2.4 Summary 35

2.5 Summary of Cautions 36

2.6 Summary of Programming Tips 36

2.7 Questions 36

2.8 Programming Exercises 38

Chapter 3:Data 39

3.1 Basic Data Types 39

3.1.1 The Integer Family 39

3.1.2 Floating-Point Types 44

3.1.3 Pointers 45

3.2 Basic Declarations 47

3.2.1 Initialization 48

3.2.2 Declaring Simple Arrays 49

3.2.3 Declaring Pointers 49

3.2.4 Implicit Declarations 51

3.3 Typedef 51

3.4 Constants 52

3.5 Scope 54

3.5.1 Block Scope 54

3.5.2 File Scope 56

3.5.3 Prototype Scope 56

3.5.4 Function Scope 56

3.6 Linkage 57

3.7 Storage Class 59

3.7.1 Initialization 60

3.8 The Static Keyword 61

3.9 Scope,Linkage,and Storage Class Example 62

3.10 Summary 64

3.11 Summary of Cautions 65

3.12 Summary of Programming Tips 65

3.13 Questions 66

Chapter 4:Statements 71

4.1 Empty Statement 71

4.2 Expression Statement 72

4.3 Statement Blocks 73

4.4 If Statement 73

4.5 While Statement 75

4.5.1 Break and Continue Statements 75

4.5.2 Execution of the While 75

4.6 For Statement 77

4.6.1 Execution of a For 77

4.7 Do Statement 79

4.8 Switch Statement 80

4.8.1 Break in a Switch 81

4.8.2 Defaults 82

4.8.3 Execution of the Switch 83

4.9 Goto Statement 84

4.10 Summary 86

4.11 Summary of Cautions 87

4.12 Summary of Programming Tips 87

4.13 Questions 87

4.14 Programming Exercises 89

Chapter 5:Operators and Expressions 93

5.1 Operators 93

5.1.1 Arithmetic 93

5.1.2 Shifting 94

5.1.3 Bitwise 95

5.1.4 Assignment 97

5.1.5 Unary 100

5.1.6 Relational 103

5.1.7 Logical 104

5.1.8 Conditional 106

5.1.9 Comma 107

5.1.10 Subscript,Function Call,and Structure Member 108

5.2 Boolean Values 109

5.3 L-values and R-values 111

5.4 Expression Evaluation 112

5.4.1 Implicit Type Conversions 112

5.4.2 Arithmetic Conversions 113

5.4.3 Properties of Operators 113

5.4.4 Precedence and Order of Evaluation 115

5.5 Summary 119

5.6 Summary of Cautions 120

5.7 Summary of Programming Tips 121

5.8 Questions 121

5.9 Programming Exercises 125

Chapter 6:Pointers 129

6.1 Memory and Addresses 129

6.1.1 Address Versus Contents 130

6.2 Values and Their Types 131

6.3 Contents of a Pointer Variable 132

6.4 Indirection Operator 133

6.5 Uninitialized and Illegal Pointers 135

6.6 The Null Pointer 136

6.7 Pointers,Indirection,and L-values 137

6.8 Pointers,Indirection,and Variables 138

6.9 Pointer Constants 138

6.10 Pointers to Pointers 139

6.11 Pointer Expressions 141

6.12 Examples 148

6.13 Pointer Arithmetic 152

6.13.1 Arithmetic Operations 153

6.13.2 Relational Operations 156

6.14 Summary 157

6.15 Summary of Cautions 159

6.16 Summary of Programming Tips 159

6.17 Questions 159

6.18 Programming Exercises 162

Chapter 7:Functions 165

7.1 Function Definition 165

7.1.1 Return Statement 167

7.2 Function Declaration 168

7.2.1 Prototypes 168

7.2.2 Default Function Assumptions 171

7.3 Function Arguments 172

7.4 ADTs and Black Boxes 176

7.5 Recursion 179

7.5.1 Tracing a Recursive Function 181

7.5.2 Recursion versus Iteration 185

7.6 Variable Argument Lists 189

7.6.1 The stdarg Macros 190

7.6.2 Limitations of Variable Arguments 190

7.7 Summary 192

7.8 Summary of Cautions 194

7.9 Summary of Programming Tips 194

7.10 Questions 194

7.11 Programming Exercises 195

Chapter 8:Arrays 197

8.1 One-Dimensional Arrays 197

8.1.1 Array Names 197

8.1.2 Subscripts 199

8.1.3 Pointers versus Subscripts 202

8.1.4 Pointer Efficiency 203

8.1.5 Arrays and Pointers 210

8.1.6 Array Names as Function Arguments 210

8.1.7 Declaring Array Parameters 212

8.1.8 Initialization 213

8.1.9 Incomplete Initialization 214

8.1.10 Automatic Array Sizing 214

8.1.11 Character Array Initialization 215

8.2 Multidimensional Arrays 215

8.2.1 Storage Order 216

8.2.2 Array Names 218

8.2.3 Subscripts 218

8.2.4 Pointers to Arrays 221

8.2.5 Multidimensional Arrays as Function Arguments 223

8.2.6 Initialization 224

8.2.7 Automatic Array Sizing 227

8.3 Arrays of Pointers 227

8.4 Summary 231

8.5 Summary of Cautions 232

8.6 Summary of Programming Tips 232

8.7 Questions 233

8.8 Programming Exercises 237

Chapter 9:Strings,Characters,and Bytes 243

9.1 String Basics 243

9.2 String Length 244

9.3 Unrestricted String Functions 245

9.3.1 Copying Strings 245

9.3.2 Concatenating Strings 246

9.3.3 Function Return Value 247

9.3.4 String Comparisons 247

9.4 Length-Restricted String Functions 248

9.5 Basic String Searching 250

9.5.1 Finding a Character 250

9.5.2 Finding Any of Several Characters 250

9.5.3 Finding a Substring 251

9.6 Advanced String Searching 251

9.6.1 Finding String Prefixes 251

9.6.2 Finding Tokens 253

9.7 Error Messages 255

9.8 Character Operations 255

9.8.1 Character Classification 255

9.8.2 Character Transformation 256

9.9 Memory Operations 257

9.10 Summary 258

9.11 Summary of Cautions 260

9.12 Summary of Programming Tips 260

9.13 Questions 261

9.14 Programming Exercises 262

Chapter 10:Structures and Unions 269

10.1 Structure Basics 269

10.1.1 Structure Declarations 270

10.1.2 Structure Members 272

10.1.3 Direct Member Access 272

10.1.4 Indirect Member Access 273

10.1.5 Self-Referential Structures 274

10.1.6 Incomplete Declarations 275

10.1.7 Initializing Structures 276

10.2 Structures,Pointers,and Members 276

10.2.1 Accessing the Pointer 277

10.2.2 Accessing the Structure 278

10.2.3 Accessing Structure Members 279

10.2.4 Accessing a Nested Structure 281

10.2.5 Accessing a Pointer Member 282

10.3 Structure Storage Allocation 283

10.4 Structures as Function Arguments 285

10.5 Bit Fields 288

10.6 Unions 291

10.6.1 Variant Records 293

10.6.2 Initializing Unions 294

10.7 Summary 295

10.8 Summary of Cautions 296

10.9 Summary of Programming Tips 296

10.10 Questions 296

10.11 Programming Exercises 300

Chapter 11:Dynamic Memory Allocation 303

11.1 Why Use Dynamic Allocation 303

11.2 Malloc and Free 304

11.3 Calloc and Realloc 305

11.4 Using Dynamically Allocated Memory 306

11.5 Common Dynamic Memory Errors 307

11.5.1 Memory Leaks 309

11.6 Memory Allocation Examples 310

11.7 Summary 317

11.8 Summary of Cautions 318

11.9 Summary of Programming Tips 318

11.10 Questions 318

11.11 Programming Exercises 319

Chapter 12:Using Structures and Pointers 321

12.1 Linked Lists 321

12.2 Singly Linked Lists 321

12.2.1 Inserting into a Singly Linked List 322

12.2.2 Other List Operations 334

12.3 Doubly Linked Lists 334

12.3.1 Inserting into a Doubly Linked List 335

12.3.2 Other List Operations 345

12.4 Summary 345

12.5 Summary of Cautions 346

12.6 Summary of Programming Tips 346

12.7 Questions 346

12.8 Programming Exercises 347

Chapter 13:Advanced Pointer Topics 351

13.1 More Pointers to Pointers 351

13.2 Advanced Declarations 353

13.3 Pointers to Functions 356

13.3.1 Callback Functions 357

13.3.2 Jump Tables 360

13.4 Command Line Arguments 362

13.4.1 Passing Command Line Arguments 363

13.4.2 Processing Command Line Arguments 365

13.5 String Literals 369

13.6 Summary 372

13.7 Summary of Cautions 373

13.8 Summary of Programming Tips 373

13.9 Questions 373

13.10 Programming Exercises 377

Chapter 14:The Preprocessor 383

14.1 Predefined Symbols 383

14.2 #define 384

14.2.1 Macros 385

14.2.2 #define Substitution 388

14.2.3 Macros versus Functions 389

14.2.4 Macro Arguments with Side Effects 390

14.2.5 Naming Conventions 391

14.2.6 #undef 392

14.2.7 Command Line Definitions 393

14.3 Conditional Compilation 394

14.3.1 If Defined 395

14.3.2 Nested Directives 396

14.4 File Inclusion 397

14.4.1 Library Includes 398

14.4.2 Local Includes 398

14.4.3 Nested File Inclusion 399

14.5 Other Directives 401

14.6 Summary 402

14.7 Summary of Cautions 403

14.8 Summary of Programming Tips 403

14.9 Questions 404

14.10 Programming Exercises 406

Chapter 15:Input/Output Functions 409

15.1 Error Reporting 409

15.2 Terminating Execution 410

15.3 The Standard I/O Library 411

15.4 ANSI I/O Concepts 411

15.4.1 Streams 412

15.4.2 FILEs 413

15.4.3 Standard I/O Constants 414

15.5 Overview of Stream I/O 415

15.6 Opening Streams 416

15.7 Closing Streams 418

15.8 Character I/O 420

15.8.1 Character I/O Macros 421

15.8.2 Undoing Character I/O 421

15.9 Unformatted Line I/O 423

15.10 Formatted Line I/O 425

15.10.1 The scanf Family 425

15.10.2 scanf Format Codes 426

15.10.3 The printf Family 430

15.10.4 printf Format Codes 433

15.11 Binary I/O 436

15.12 Flushing and Seeking Functions 438

15.13 Changing the Buffering 440

15.14 Stream Error Functions 441

15.15 Temporary Files 442

15.16 File Manipulation Functions 442

15.17 Summary 443

15.18 Summary of Cautions 446

15.19 Summary of Programming Tips 446

15.20 Questions 446

15.21 Programming Exercises 448

Chapter 16:Standard Library 453

16.1 Integer Functions 453

16.1.1 Arithmetic<stdlib.h> 453

16.1.2 Random Numbers<stdlib.h> 454

16.1.3 String Conversion<stdlib.h> 455

16.2 Floating-Point Functions 457

16.2.1 Trigonometry<math.h> 458

16.2.2 Hyperbolic<math.h> 458

16.2.3 Logarithm and Exponent<math.h> 458

16.2.4 Floating-Point Representation<math.h> 459

16.2.5 Power<math.h> 459

16.2.6 Floor,Ceiling,Absolute Value,and Remainder<math.h> 460

16.2.7 String Conversion<stdlib.h> 460

16.3 Date and Time Functions 461

16.3.1 Processor Time<time.h> 461

16.3.2 Time of Day<time.h> 462

16.4 Nonlocal Jumps<setjmp.h> 465

16.4.1 Example 466

16.4.2 When to Use Nonlocal Jumps 468

16.5 Signals 469

16.5.1 Signal Names<signal.h> 469

16.5.2 Processing Signals<signal.h> 470

16.5.3 Signal Handlers 472

16.6 Printing Variable Argument Lists<stdarg.h> 474

16.7 Execution Environment 474

16.7.1 Terminating Execution<stdlib.h> 475

16.7.2 Assertions<assert.h> 475

16.7.3 The Environment<stdlib.h> 477

16.7.4 Executing System Commands<stdlib.h> 477

16.8 Sorting and Searching<stdlib.h> 477

16.9 Locales 480

16.9.1 Numeric and Monetary Formatting<locale.h> 481

16.9.2 Strings and Locales<string.h> 484

16.9.3 Effects of Changing the Locale 485

16.10 Summary 485

16.11 Summary of Cautions 487

16.12 Summary of Programming Tips 488

16.13 Questions 488

16.14 Programming Exercises 490

Chapter 17:Classic Abstract Data Types 493

17.1 Memory Allocation 493

17.2 Stacks 494

17.2.1 Stack Interface 494

17.2.2 Implementing a Stack 494

17.3 Queues 505

17.3.1 Queue Interface 505

17.3.2 Implementing a Queue 507

17.4 Trees 512

17.4.1 Insertions into a Binary Search Tree 513

17.4.2 Deletions from a Binary Search Tree 514

17.4.3 Searching a Binary Search Tree 514

17.4.4 Tree Traversals 515

17.4.5 Binary Search Tree Interface 516

17.4.6 Implementing a Binary Search Tree 516

17.5 Improvements in Implementation 526

17.5.1 Having More Than One Stack 526

17.5.2 Having More Than One Type 526

17.5.3 Name Clashes 527

17.5.4 Standard Libraries of ADTs 528

17.6 Summary 531

17.7 Summary of Cautions 532

17.8 Summary of Programming Tips 533

17.9 Questions 533

17.10 Programming Exercises 535

Chapter 18:Runtime Environment 537

18.1 Determining the Runtime Environment 537

18.1.1 Test Program 539

18.1.2 Static Variables and Initialization 541

18.1.3 The Stack Frame 542

18.1.4 Register Variables 543

18.1.5 Length of External Identifiers 545

18.1.6 Determining the Stack Frame Layout 545

18.1.7 Expression Side Effects 552

18.2 Interfacing With Assembly Language 554

18.3 Runtime Efficiency 555

18.3.1 Improving Efficiency 556

18.4 Summary 559

18.5 Summary of Cautions 559

18.6 Summary of Programming Tips 560

18.7 Questions 560

18.8 Programming Exercises 560

Appendix:Selected Problem Solutions 561