logo资料库

Pointers on C 英文版.pdf

第1页 / 共609页
第2页 / 共609页
第3页 / 共609页
第4页 / 共609页
第5页 / 共609页
第6页 / 共609页
第7页 / 共609页
第8页 / 共609页
资料共609页,剩余部分请下载后查看
Cover
Chapter 1 -- A Quick Start
1.1 Introduction
1.1.1 Spacing and Comments
1.1.2 Preprocessor Directives
1.1.3 The Main Function
1.1.4 The read_column_numbers Function
1.2 Other Capabilities
1.3 Compiling
1.4 Summary
1.5 Summary of Cautions
1.6 Summary of Programming Tips
1.7 Questions
1.8 Programming Exercises
Chapter 2 -- Basic Concepts
2.1 Environments
2.1.1 Translation
Filename Conventions
Compiling and Linking
2.1.2 Execution
2.2 Lexical Rules
2.2.1 Characters
2.2.2 Comments
2.2.3 Free Form Source Code
2.2.4 Identifiers
2.2.5 Form of a Program
2.3 Program Style
2.4 Summary
2.5 Summary of Cautions
2.6 Summary of Programming Tips
2.7 Questions
2.8 Programming Exercises
Chapter 3 -- Data
3.1 Basic Data Types
3.1.1 The Integer Family
Integer Literals
Enumerated Type
3.1.2 Floating-Pint Types
3.1.3 Pointers
Pointer Constants
String Literals
3.2 Basic Declarations
3.2.1 Initialization
3.2.2 Declaring Simple Arrays
3.2.3 Declaring Pointers
3.2.4 Implicit Declarations
3.3 Typedef
3.4 Constants
3.5 Scope
3.5.1 Block Scope
3.5.2 File Scope
3.5.3 Prototype Scope
3.5.4 Function Scope
3.6 Linkage
3.7 Storage Class
3.7.1 Initialization
3.8 The Static Keyword
3.9 Scope, Linkage, and Storage Class Example
3.10 Summary
3.11 Summary of Cautions
3.12 Summary of Programming Tips
3.13 Questions
Chapter 4 -- Statements
4.1 Empty Statement
4.2 Expression Statement
4.3 Statement Blocks
4.4 If Statement
4.5 While Statement
4.5.1 Break and Continue Statements
4.5.2 Execution of the While
4.6 For Statement
4.6.1 Execution of a For
4.7 Do statement
4.8 Switch Statement
4.8.1 break in a switch
4.8.2 Defaults
4.8.3 Execution of the Switch
4.9 Goto Statement
4.10 Summary
4.11 Summary of Cautions
4.12 Summary of Programming Tips
4.13 Questions
4.14 Programming Exercises
Chapter 5 -- Operators and Expressions
5.1 Operators
5.1.1 Arithmetic
5.1.2 Shifting
5.1.3 Bitwise
Bit Manipulation
5.1.4 Assignment
Compound Assignment
5.1.5 Unary
5.1.6 Relational
5.1.7 Logical
5.1.8 Conditional
5.1.9 Comma
5.1.10 Subscript, Function Call, and Structure Member
5.2 Boolean Values
5.3 L-values and R-values
5.4 Expression Evaluation
5.4.1 Implicit Type Conversions
5.4.2 Arithmetic Conversions
5.4.3 Properties of Operators
5.4.4 Precedence and Order of Evaluation
5.5 Summary
5.6 Summary of Cautions
5.7 Summary of Programming Tips
5.8 Summary
5.9 Programming Exercises
Chapter 6 -- Pointers
6.1 Memory and Addresses
6.1.1 Address Versus Contents
6.2 Values and Their Types
6.3 Contents of a Pointer Variable
6.4 Indirection Operator
6.5 Uninitialized and Illegal Pointer
6.6 The Null Pointer
6.7 Pointers, Indirection, and L-values
6.8 Pointers, Indirection, and Variables
6.9 Pointer Constants
6.10 Pointers to Pointers
6.11 Pointer Expressions
6.12 Examples
6.13 Pointer Arithmetic
6.13.1 Arithmetic Operations
6.13.2 Relational Operations
6.14 Summary
6.15 Summary of Cautions
6.16 Summary of Programming Tips
6.17 Questions
6.18 Programming Exercises
Chapter 7 -- Functions
7.1 Function Definition
7.1.1 Return Statement
7.2 Function Declaration
7.2.1 Prototypes
7.2.2 Default Function Assumptions
7.3 Function Arguments
7.4 ADTs and Black Boxes
7.5 Recursion
7.5.1 Tracing a Recursive Function
7.5.2 Recursion versus Iteration
7.6 Variable Argument Lists
7.6.1 The stdarg Macros
7.6.2 Limitations of Variable Arguments
7.7 Summary
7.8 Summary of Cautions
7.9 Summary of Programming Tips
7.10 Questions
7.11 Programming Exercises
Chapter 8 -- Arrays
8.1 One-Dimensional Arrays
8.1.1 Array Names
8.1.2 Subscripts
8.1.3 Pointers versus Subscripts
8.1.4 Pointer Efficiency
Switching to Pointers
Bringing Back the Counter
Register Pointer Variables
Eliminating the Counter
Conclusions
8.1.5 Arrays and Pointers
8.1.6 Array Names as Function Arguments
8.1.7 Declaring Array Parameters
8.1.8 Initialization
Static and Automatic Initialization
8.1.9 Incomplete Initialization
8.1.10 Automatic Array Sizing
8.1.11 Character Array Initialization
8.2 Multidimensional Arrays
8.2.1 Storage Order
8.2.2 Array Names
8.2.3 Subscripts
8.2.4 Pointers to Arrays
8.2.5 Multidimensional Arrays as Function Arguments
8.2.6 Initialization
8.2.7 Automatic Array Sizing
8.3 Arrays of Pointers
8.4 Summary
8.5 Summary of Cautions
8.6 Summary of Programming Tips
8.7 Questions
8.8 Programming Exercises
Chapter 9 -- Strings, Characters, and Bytes
9.1 String Basics
9.2 String Length
9.3 Unrestricted String Functions
9.3.1 Copying Strings
9.3.2 Concatenating Strings
9.3.3 Function Return Value
9.3.4 String Comparisons
9.4 Length-Restricted String Functions
9.5 Basic String Searching
9.5.1 Finding a Character
9.5.2 Finding Any of Several Characters
9.5.3 Finding a Substring
9.6 Advanced String Searching
9.6.1 Finding String Prefixes
9.6.2 Finding Tokens
9.7 Error Messages
9.8 Character Operations
9.8.1 Character Classification
9.8.2 Character Transformation
9.9 Memory Operations
9.10 Summary
9.11 Summary of Cautions
9.12 Summary of Programming Tips
9.13 Questions
9.14 Programming Exercises
Chapter 10 -- Structures and Unions
10.1 Structure Basics
10.1.1 Structure Declarations
10.1.2 Structure Members
10.1.3 Direct Member Access
10.1.4 Indirect Member Access
10.1.5 Self-Referential Structures
10.1.6 Incomplete Declarations
10.1.7 Initializing Structures
10.2 Structures, Pointers, and Members
10.2.1 Accessing the Pointer
10.2.2 Accessing the Structure
10.2.3 Accessing Structure Members
10.2.4 Accessing a Nested Structure
10.2.5 Accessing a Pointer Member
10.3 Structure Storage Allocation
10.4 Structures as Function Arguments
10.5 Bit Fields
10.6 Unions
10.6.1 Variant Records
10.6.2 Initializing Unions
10.7 Summary
10.8 Summary of Cautions
10.9 Summary of Programming Tips
10.10 Questions
10.11 Programming Exercises
Chapter 11 -- Dynamic Memory Allocation
11.1 Why Use Dynamic Allocation
11.2 Malloc and Free
11.3 Calloc and Realloc
11.4 Using Dynamically Allocated Memory
11.5 Common Dynamic Memory Errors
11.5.1 Memory Leaks
11.6 Memory Allocation Examples
11.7 Summary
11.8 Summary of Cautions
11.9 Summary of Programming Tips
11.10 Questions
11.11 Programming Exercises
Chapter 12 -- Using Structures and Pointers
12.1 Linked Lists
12.2 Singly Linked Lists
12.2.1 Inserting into a Singly Linked List
Debugging the Insert Function
Optimizing the Insert Function
12.2.2 Other List Operations
12.3 Doubly Linked Lists
12.3.1 Inserting into a Doubly Linked List
Simplifying the Insert Function
12.3.2 Other List Operations
12.4 Summary
12.5 Summary of Cautions
12.6 Summary of Programming Tips
12.7 Questions
12.8 Programming Exercises
Chapter 13 -- Advanced Pointers Topics
13.1 More Pointers to Pointers
13.2 Advanced Declarations
13.3 Pointers to Functions
13.3.1 Callback Functions
13.3.2 Jump Tables
13.4 Command Line Arguments
13.4.1 Passing Command Line Arguments
13.4.2 Processing Command Line Arguments
13.5 String Literals
13.6 Summary
13.7 Summary of Cautions
13.8 Summary of Programming Tips
13.9 Questions
13.10 Programming Exercises
Chapter 14 -- The Preprocessor
14.1 Predefined Symbols
14.2 #define
14.2.1 Macros
14.2.2 #define Substitution
14.2.3 Macros versus Functions
14.2.4 Macro Arguments with Side Effects
14.2.5 Naming Conventions
14.2.6 #undef
14.2.7 Command Line Definitions
14.3 Conditional Compilation
14.3.1 If Defined
14.3.2 Nested Directives
14.4 File Inclusion
14.4.1 Library Includes
14.4.2 Local Includes
14.4.3 Nested File Inclusion
14.5 Other Directives
14.6 Summary
14.7 Summary of Cautions
14.8 Summary of Programming Tips
14.9 Questions
14.10 Programming Exercises
Chapter 15 -- Input/Output Functions
15.1 Error Reporting
15.2 Terminating Execution
15.3 The Standard I/O Library
15.4 ANSI I/O Concepts
15.4.1 Streams
Text Streams
Binary Streams
15.4.2 FILEs
15.4.3 Standard I/O Constants
15.5 Overview of Stream I/O
15.6 Opening Streams
15.7 Closing Streams
15.8 Character I/O
15.8.1 Character I/O Macros
15.8.2 Undoing Character I/O
15.9 Unformatted Line I/O
15.10 Formatted Line I/O
15.10.1 The scanf Family
15.10.2 scanf Format Codes
15.10.3 The printf Family
15.10.4 printf Format Codes
15.11 Binary I/O
15.12 Flushing and Seeking Functions
15.13 Changing the Buffering
15.14 Stream Error Functions
15.15 Temporary Files
15.16 File Manipulation Functions
15.17 Summary
15.18 Summary of Cautions
15.19 Summary of Programming Tips
15.20 Questions
15.21 Programming Exercises
Chapter 16 -- Standard Library
16.1 Integer Functions
16.1.1 Arithmetic
16.1.2 Random Numbers
16.1.3 String Conversion
16.2 Floating-Point Functions
16.2.1 Trigonometry
16.2.2 Hyperbolic
16.2.3 Logarithm and Exponent
16.2.4 Floating-point Representation
16.2.5 Power
16.2.6 Floor, Ceiling, Absolute Value, and Remainder
16.2.7 String Conversion
16.3 Date and Time Functions
16.3.1 Processor Time
16.3.2 Time of Day
Date and Time Conversions
16.4 Nonlocal Jumps
16.4.1 Example
16.4.2 When to Use Nonlocal Jumps
16.5 Signals
16.5.1 Signal Names
16.5.2 Processing Signals
16.5.3 Signal Handlers
Volatile Data
Returning From a Handler
16.6 Printing Variable Argument Lists
16.7 Execution Environment
16.7.1 Terminating Execution
16.7.2 Assertions
16.7.3 The Environment
16.7.4 Executing System Commands
16.8 Sorting and Searching
16.9 Locales
16.9.1 Numeric and Monetary Formatting
Numeric Formatting
Monetary Formatting
16.9.2 Strings and Locales
16.9.3 Effects of Changing the Locale
16.10 Summary
16.11 Summary of Cautions
16.12 Summary of Programming Tips
16.13 Questions
16.14 Programming Exercises
Chapter 17 -- Classic Abstract Data Types
17.1 Memory Allocation
17.2 Stacks
17.2.1 Stack Interface
17.2.2 Implementing a Stack
An Arrayed Stack
A Dynamically Arrayed Stack
A Linked Stack
17.3 Queues
17.3.1 Queue Interface
17.3.2 Implementing a Queue
An Arrayed Queue
Dynamically Arrayed and Linked Queues
17.4 Trees
17.4.1 Insertions into a Binary Search Tree
17.4.2 Deletions from a Binary Search Tree
17.4.3 Searching a Binary Search Tree
17.4.4 Tree Traversals
17.4.5 Binary Search Tree Interface
17.4.6 Implementing a Binary Search Tree
An Arrayed, Binary Search Tree
A Linked Binary Search Tree
Variations on the Tree Interface
17.5 Improvements in Implementation
17.5.1 Having More Than One Stack
17.5.2 Having More Than One Type
17.5.3 Name Clashes
17.5.4 Standard Libraries of ADTs
17.6 Summary
17.7 Summary of Cautions
17.8 Summary of Programming Tips
17.9 Questions
17.10 Programming Exercises
Chapter 18 -- Runtime Environment
18.1 Determining the Runtime Environment
18.1.1 Test Program
18.1.2 Static Variables and Initialization
18.1.3 The Stack Frame
18.1.4 Register Variables
18.1.5 Length of External Identifiers
18.1.6 Determining the Stack Frame Layout
Passing Function Arguments
Function Prologue
Argument Ordering on the Stack
Final Stack Frame Layout
Function Epilogue
Return Values
18.1.7 Expression Side Effects
18.2 Interfacing With Assembly Language
18.3 Runtime Efficiency
18.3.1 Improving Efficiency
18.4 Summary
18.5 Summary of Cautions
18.6 Summary of Programming Tips
18.7 Questions
18.8 Programming Exercises
APPENDIX -- Selected Problem Solutions
Chapter 1 Questions
Chapter 1 Programming Exercises
Chapter 2 Questions
Chapter 2 Programming Exercises
Chapter 3 Questions
Chapter 4 Questions
Chapter 4 Programming Exercises
Chapter 5 Questions
Chapter 5 Programming Exercises
Chapter 6 Questions
Chapter 6 Programming Exercises
Chapter 7 Questions
Chapter 7 Programming Exercises
Chapter 8 Questions
Chapter 8 Programming Exercises
Chapter 9 Questions
Chapter 9 Programming Exercises
Chapter 10 Questions
Chapter 10 Programming Exercises
Chapter 11 Questions
Chapter 11 Programming Exercises
Chapter 12 Questions
Chapter 12 Programming Exercises
Chapter 13 Questions
Chapter 13 Programming Exercises
Chapter 14 Questions
Chapter 14 Programming Exercises
Chapter 15 Questions
Chapter 15 Programming Exercises
Chapter 16 Questions
Chapter 16 Programming Exercises
Chapter 17 Questions
Chapter 17 Programming Exercises
Chapter 18 Questions
Chapter 18 Programming Exercises
orced version 1.0, by vivisimo, and posted in http://library.nu last modified: 2011.06.05 1 A Quick Start 1.1 Introduction Itisalwaysdifficulttostartdescribingaprogramminglanguagebecauselittle details do not make much sense until one knows enough to understand the big picture.Inthischapter,Itrytogiveyouaglimpseofthebigpicturebylookingata sampleprogramandexplainingitsworkingslinebyline.Thissampleprogramalso showsyouhowfamiliarproceduresareaccomplishedinC.Thisinformationplusthe othertopicsdiscussedinthechapterintroduceyoutothebasicsoftheClanguageso thatyoucanbeginwritingusefulprograms. The program we dissect reads text from the standard input, modifies it, and writesittothestandardoutput.Programl.lfirstreadsalistofcolumnnumbers.These numbers are pairs and indicate ranges of columns in the input line. The list is terminatedwithanegativenumber.Theremaininginputlinesarereadandprinted, thentheselectedcolumnsfromtheinputlinesareextractedandprimed.Notethatthe firstcolumninalineisnumberzero.Forexample,iftheinputis 4 9 12 20 -1 abcdefghijklmnopqrstuvwxyz Hello there, how are you? I am fine, thanks. See you! Bye thentheprogramwouldproduce: Original input : abcdefghijklmnopqxstuvwxyz Rearranged line: efghijmnopqrstu
Download at http://www.pin5i.com/ 2 Chapter 1 A Quick Start Original input : Hello there, how are you? Rearranged line: o ther how are Original input : I am fine, thanks. Rearranged line: fine, thanks. Original input : See you! Rearranged line: you! Original input : Bye Rearranged line: The important point about this program is that it illustrates most of the basic techniquesyouneedtoknowtobeginwritingCprograms. /* ** This program reads input lines from standard input and prints ** each input line, followed by just some portions of the line, to ** the standard output. ** ** The first input is a lint of column numbers, which ends with a ** negative number. The column numbers are paired and specify ** ranges of columns from the input line that are to be printed. ** For example, 0 3 10 12 -1 indicates that only columns 0 through 3 ** and columns 10 through 12 will be printed. */ #include #inc1ude #include #define MAX_COLS #define MAX_INPUT int read_column_numbers( int columns[], int max ); void rearrange( char *output, char const *input, int n_columns, int const columns[] ); int main( void ) { Program1.1 Rearrangecharacters /* # of columns to process */ /* the columns to process */ /*array for input line */ /*array for output line */ int n_columns; int columns[MAX_COLS]; char input[MAX_INPUT]; char output[MAX_INPUT]; 20 1000 /* max len of input & output lines */ /* max # of columns to process */ continue
Download at http://www.pin5i.com/ 1.1 Introduction 3 /* ** Read the list of column numbers */ n_columns = read_column_numbers( columns, MAX_COLS ); /* ** Discard the rest of the line that contained the final Program1.1 Rearrangecharacters continue /* ** Read, process and print the remaining lines of input */ while( gets(input ) != NULL ){ } return EXIT_SUCCESS; printf( "Original input : %s\n", input ); rearrange( output, input, n_columns, columns ); printf( "Rearranged line: %s\n", output ); int num = 0; int ch; } /* ** Read the list of column numbers, ignoring any beyond the specified ** maximum. */ int read_column_numbers( int columns[], int max ) { /* ** Make sure we have an even number of inputs, as they are ** supposed to be paired. */ if( num % 2 != 0 ){ } /* ** Get the numbers, stopping at eof or when a number is < 0. */ while( num < max && scanf( "%d", &columns[num] ) == 1 &&columns[num] >= 0 ) num +=1; puts( "Last column number is not paired." ); exit( EXIT_FAILURE );
Download at http://www.pin5i.com/ Chapter 1 A Quick Start in n_columns, int const columns[] ) len = strlen( input ); output_col = 0; /* subscript for columns array */ /* output column counter */ /* length of input line */ int col; int output_col; int len; ** number. */ while( (ch = getchar()) != EOF && ch != '\n' ) return num; } /* ** Process a line of input by concatenating the characters from ** the indicated columns. The output line is the NUL terminated, */ void rearrange( char *output, char const *input, { Program1.1 Rearrangecharacters /* ** Process each pair of column numbers. */ for( col = 0; col < n_columns; col += 2 ){ /* ** If the input line isn't this long or the output ** array is full, we're done */ if( columns[col] >= len || output_col == MAX_INPUT – 1 ) /* ** If there isn't room in the output array, only copy ** what will fit. */ if( output_col + nchars > MAX_INPUT – 1) /* nchars = MAX_INPUT – output_col – 1; int nchars = columns[col + 1] – columns[col] + 1; break; 4 ; continue
Download at http://www.pin5i.com/ 1.1 Introduction 5 ** Copy the relevant data. */ strncpy( output + output_col, input + columns[col], output_col += nchars; nchars ); output[output_col] = '\0'; } } Program1.1 Rearrangecharacters 1.1.1 Spacing and Comments rearrang.c Now,let’stakeacloserlookatthisprogram.Thefirstpointtonoticeisthespacingof theprogram:theblanklinesthatseparatedifferentpartsfromoneanother,theuseof tabstoindentstatementstodisplaytheprogramstructure,andsoforth.Cisafree formlanguage,sotherearenorulesastohowyoumustwritestatements.However,a littledisciplinewhenwritingtheprogrampaysofflaterbymakingiteasiertoread andmodify.Moreonthisissueinabit. Whileitisimportanttodisplaythestructureoftheprogramclearly,itiseven more important to tell the reader what the program does and how it works. Commentsfulfillthisrole /* ** This program reads input lines from the standard input and prints ** each input line, followed by just: some portions of the lines, to ** the standard output . ** ** The first input; is a list of column numbers, which ends with a ** negative number . The column numbers are paired and specify ** ranges of columns from the input line that are to be printed. ** For example, 0 3 l0 12 —l indicates that only columns 0 through 3 ** and columns 10 through 12 will be printed */ This block of text is a comment. Comments begin with the /* characters and endwiththe*/characters.TheymayappearanywhereinaCprograminwhichwhite space may appear. However, comments cannot contain other comments, that is, the First*/terminatesthecommentnomatterhowmany/*shaveappearedearlier.
Download at http://www.pin5i.com/ 6 Chapter 1 A Quick Start Commentsaresometimesusedinotherlanguagestocommentoutcode,thus removingthecodefromtheprogramwithoutphysicallydeletingitfromthesource file.ThispracticeisabadideainC,becauseitwon’tworkifthecodeyou‘retryingto getridofhasanycommentsinit.AbetterwaytologicallydeletecodeinaCprogram isthe#ifdirective.Whenusedlikethis: #if 0 #endif statements theprogramstatementsbetweenthe#ifandthe#endifareeffectivelyremovedfrom theprogram.Commentscontainedinthestatementshavenoeffectonthisconstruct, thusitisamuchsaferwaytoaccomplishtheobjective.Thereismuchmorethatyou candowiththisdirective,whichIexplainfullyinChapter14. 1.1.2 Preprocessor Directives #include #include #include #define MAX_COLS #define MAX_INPUT 20 1000 /* max len of input & output lines */ /* max # of columns to process */ Thesefivelinesarecalledpreprocessordirectives,orjustdirectives,becausethey areinterpretedbythepreprocessorThepreprocessorreadsthesourcecode,modifies itasindicatedbyanypreprocessordirectives,andthenpassesthemodifiedcodeto thecompiler. Inoursampleprogram,thepreprocessorreplacesthefirst#includestatement withthecontentsofthelibraryheadernamedstdio.h;theresultisthesameasifthe contents of stdio.h had been written verbatim at this point in the source file. The secondandthirddirectivesdothesamewith stdlib.handstring.h. Thestdio.hheadergivesusaccesstofunctionsfromtheStandardI/OLibrary,a collection of functions that perform input and output, stdlib.h defines the EXIT_SUCCESS and EXIT_FAILURE symbols. We need string.h to use the string manipulationfunctions. Thistechniqueisalsoahandywaytomanageyourdeclarationsiftheyareneededin severaldifferentsourcefiles—youwritethedeclarationsinaseparatefileandthenuse #includetoreadthemintoeachrelevantsourcetile.Thusthereisonlyonecopyofthe declarations;theyarenotduplicatedinmanydifferentplaces,whichwouldbemore errorpronetomaintain. TIP
Download at http://www.pin5i.com/ 1.1 Introduction 7 TIP Theotherdirectiveis #define,whichdefinesthename MAX_COLStobethevalue20, andMAX_INPUTtobethevalue1000.Wherevereithernameappearslaterinthesource tile, it is replaced by the appropriate value. Because they are defined as literal constants,thesenamescannotbeusedinsomeplaceswhereordinaryvariablescanbe used(forexample,ontheleftsideofanassignment).Makingtheirnamesuppercase servesasareminderthattheyarenotordinaryvariables.#definedirectivesareused forthesamekindsofthingsassymbolicconstantsinotherlanguagesandforthesame reasons.Ifwelaterdecidethat20columnsarenotenough,wecansimplychangethe definitionofMAX_COLS.Thereisnoneedtohuntthroughtheprogramlookingfor20’s tochangeandpossiblymissingoneorchanginga20thathadnothingtodowiththe maximumnumberofcolumns. int read_column_numbers( int columns[], int max ); void rearrange( char *output, char const *input, int n_columns, int const columns[] ); These declarations are called function prototypes. They tell the compiler about thecharacteristicsoffunctionsthataredefinedlaterinthesourcetile.Thecompiler canthencheckcallstothesefunctionsforaccuracy.Eachprototypebeginswithatype namethatdescribesthevaluethatisreturned.Thetypenameisfollowedbythename of function are next, so read_column_numbers returns an integer and takes two arguments, an array of integersandanintegerscalar.Theargumentnamesarenotrequired;Igivethemhere toserveasareminderofwhateachargumentissupposedtobe. function. The arguments expected by the the Therearrangefunctiontakesfourarguments.Thefirstandsecondarepointers. A pointer specifies where a value resides in the computer’s memory, much like a housenumberspecifieswhereaparticularfamilyresidesonastreet.Pointersarewhat givetheClanguageitspowerandarecoveredingreatdetailstartinginChapter6. Thesecondandfourthargumentsaredeclaredconst,whichmeansthatthefunction promises not to modify the callers arguments. The keyword void indicates that the functiondoesnotreturnanyvalueatall;suchafunctionwouldbecalledaprocedurein otherlanguages. If the source code for this program was contained in several source tiles, function prototypes would have to be written in each tile using the function. Putting the prototypes in header files and using a #include to access them avoids the maintenanceproblemcausedbyhavingmultiplecopiesofthesamedeclarations. TIP
分享到:
收藏