5 11 Function Pointers Pointers to functions Contain

  • Slides: 45
Download presentation
5. 11 Function Pointers • Pointers to functions – Contain address of function –

5. 11 Function Pointers • Pointers to functions – Contain address of function – Similar to how array name is address of first element – Function name is starting address of code that defines function • Function pointers can be – – Passed to functions Returned from functions Stored in arrays Assigned to other function pointers 2003 Prentice Hall, Inc. All rights reserved.

5. 11 Function Pointers • Calling functions using pointers – Assume parameter: • bool

5. 11 Function Pointers • Calling functions using pointers – Assume parameter: • bool ( *compare ) ( int, int ) – Execute function with either • ( *compare ) ( int 1, int 2 ) – Dereference pointer to function to execute OR • compare( int 1, int 2 ) – Could be confusing • User may think compare name of actual function in program 2003 Prentice Hall, Inc. All rights reserved.

1 2 3 // Fig. 5. 25: fig 05_25. cpp // Multipurpose sorting program

1 2 3 // Fig. 5. 25: fig 05_25. cpp // Multipurpose sorting program using function pointers. #include <iostream> 4 5 6 7 using std: : cout; using std: : cin; using std: : endl; 8 9 #include <iomanip> 10 11 using std: : setw; 12 13 14 15 16 17 // prototypes void bubble( int [], const int, bool (*)( int, int ) ); void swap( int * const, int * const ); bool ascending( int, int ); bool descending( int, int ); 18 19 20 21 22 23 24 int main() { const int array. Size = 10; int order; int counter; int a[ array. Size ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; Outline fig 05_25. cpp (1 of 5) Parameter is pointer to function that receives two integer parameters and returns bool result. 25 2003 Prentice Hall, Inc. All rights reserved.

26 27 28 29 30 31 32 33 cout << "Enter 1 to sort

26 27 28 29 30 31 32 33 cout << "Enter 1 to sort in ascending order, n" << "Enter 2 to sort in descending order: " ; cin >> order; cout << "n. Data items in original ordern" ; // output original array for ( counter = 0; counter < array. Size; counter++ ) cout << setw( 4 ) << a[ counter ]; 34 35 36 37 38 39 40 // sort array in ascending order; pass function ascending // as an argument to specify ascending sorting order if ( order == 1 ) { bubble( a, array. Size, ascending ); cout << "n. Data items in ascending ordern" ; } 41 42 43 44 45 46 47 // sort array in descending order; pass function descending // as an agrument to specify descending sorting order else { bubble( a, array. Size, descending ); cout << "n. Data items in descending ordern" ; } Outline fig 05_25. cpp (2 of 5) 48 2003 Prentice Hall, Inc. All rights reserved.

49 50 51 // output sorted array for ( counter = 0; counter <

49 50 51 // output sorted array for ( counter = 0; counter < array. Size; counter++ ) cout << setw( 4 ) << a[ counter ]; 52 53 cout << endl; 54 55 return 0; fig 05_25. cpp (3 of 5) // indicates successful termination 56 57 } // end main 58 59 60 61 62 63 64 65 // multipurpose bubble sort; parameter compare is a pointer to functionorder that receives two // the comparison function that determines sorting integer parameters and returns void bubble( int work[], const int size, bool (*compare)( int, int ) ) bool result. { // loop to control passes Parentheses necessary to for ( int pass = 1; pass < size; pass++ ) 66 67 68 69 70 71 72 Outline compare is pointer to indicate pointer to function // loop to control number of comparisons per pass Call- passed function for ( int count = 0; count < size 1; count++ ) compare; dereference pointer execute function. out of to order, swap them // if adjacent elements are if ( (*compare)( work[ count ], work[ count + 1 ] ) ) swap( &work[ count ], &work[ count + 1 ] ); 2003 Prentice Hall, Inc. All rights reserved.

73 74 } // end function bubble 75 76 77 78 79 80 81

73 74 } // end function bubble 75 76 77 78 79 80 81 82 // swap values at memory locations to which // element 1 Ptr and element 2 Ptr point void swap( int * const element 1 Ptr, int * const element 2 Ptr ) { int hold = *element 1 Ptr; *element 1 Ptr = *element 2 Ptr; *element 2 Ptr = hold; 83 84 } // end function swap 85 86 87 88 89 90 91 92 Outline fig 05_25. cpp (4 of 5) // determine whether elements are out of order // for an ascending order sort bool ascending( int a, int b ) { return b < a; // swap if b is less than a } // end function ascending 93 2003 Prentice Hall, Inc. All rights reserved.

94 95 96 97 98 99 100 // determine whether elements are out of

94 95 96 97 98 99 100 // determine whether elements are out of order // for a descending order sort bool descending( int a, int b ) { return b > a; // swap if b is greater than a } // end function descending Enter 1 to Enter 2 to Data items 2 6 Data items 2 4 fig 05_25. cpp (5 of 5) fig 05_25. cpp output (1 of 1) sort in ascending order, sort in descending order: 1 in original order 4 8 10 12 89 68 in ascending order 6 8 10 12 37 45 Outline 45 37 68 89 Enter 1 to sort in ascending order, Enter 2 to sort in descending order: 2 Data items in original order 2 6 4 8 10 12 89 68 Data items in descending order 89 68 45 37 12 10 8 6 45 37 4 2 2003 Prentice Hall, Inc. All rights reserved.

5. 11 Function Pointers • Arrays of pointers to functions – Menu driven systems

5. 11 Function Pointers • Arrays of pointers to functions – Menu driven systems – Pointers to each function stored in array of pointers to functions • All functions must have same return type and same parameter types – Menu choice subscript into array of function pointers 2003 Prentice Hall, Inc. All rights reserved.

1 2 3 // Fig. 5. 26: fig 05_26. cpp // Demonstrating an array

1 2 3 // Fig. 5. 26: fig 05_26. cpp // Demonstrating an array of pointers to functions. #include <iostream> 4 5 6 7 using std: : cout; using std: : cin; using std: : endl; 8 9 10 11 12 // function prototypes void function 1( int ); void function 2( int ); void function 3( int ); 13 14 15 16 17 18 int main() Array initialized with names { of threethat functions; // initialize array of 3 pointers to functions each function // take an int argument and return void names are pointers. void (*f[ 3 ])( int ) = { function 1, function 2, function 3 }; 19 20 int choice; 21 22 23 cout << "Enter a number between 0 and 2, 3 to end: " ; cin >> choice; Outline fig 05_26. cpp (1 of 3) 24 2003 Prentice Hall, Inc. All rights reserved.

25 26 // process user's choice while ( choice >= 0 && choice <

25 26 // process user's choice while ( choice >= 0 && choice < 3 ) { 27 28 29 30 // invoke function at location choice in array f // and pass choice as an argument (*f[ choice ])( choice ); 31 32 33 34 } 35 36 cout << "Program execution 37 38 return 0; Outline fig 05_26. cpp (2 of 3) cout << "Enter a number between 0 and 2, 3 to end: " ; cin >> choice; Call chosen function by dereferencing corresponding completed. " element<<inendl; array. // indicates successful termination 39 40 } // end main 41 42 43 44 45 void function 1( int a ) { cout << "You entered " << a << " so function 1 was callednn" ; 46 47 } // end function 1 48 2003 Prentice Hall, Inc. All rights reserved.

49 50 51 52 void function 2( int b ) { cout << "You

49 50 51 52 void function 2( int b ) { cout << "You entered " << b << " so function 2 was callednn" ; 53 54 } // end function 2 55 56 57 58 59 void function 3( int c ) { cout << "You entered " << c << " so function 3 was callednn" ; 60 61 } // end function 3 Outline fig 05_26. cpp (3 of 3) fig 05_26. cpp output (1 of 1) Enter a number between 0 and 2, 3 to end: 0 You entered 0 so function 1 was called Enter a number between 0 and 2, 3 to end: 1 You entered 1 so function 2 was called Enter a number between 0 and 2, 3 to end: 2 You entered 2 so function 3 was called Enter a number between 0 and 2, 3 to end: 3 Program execution completed. 2003 Prentice Hall, Inc. All rights reserved.

Memory It is the job of the Operating System to • Manage the allocation

Memory It is the job of the Operating System to • Manage the allocation of memory to processes • Keep track of what memory/addresses each process is allowed to access • Reserve portion of memory for use by the OS • Enforce protection of memory space of each process 2003 Prentice Hall, Inc. All rights reserved.

 • Pointer – a variable whose value is a memory address • Pointee

• Pointer – a variable whose value is a memory address • Pointee – the value in memory whose address is stored in a pointer – the pointee is the target of the pointer. • A pointer may or may not have a target. Pointers without targets should be set to 0 or NULL.

int x = 4, y = 99; int *p 1, *p 2; p 1

int x = 4, y = 99; int *p 1, *p 2; p 1 = &x; p 2 = &y; *p 1 = 3; cout << *p 1 << “ “<< *p 2; p 2 = p 1; cout << *p 1 << “ “<< *p 2;

float i, x, *p, *q; p = &i; *p = 10. 0; q =

float i, x, *p, *q; p = &i; *p = 10. 0; q = &x; *q = 8. 6; cout << x << endl; cout << I << endl; *p = 9. 5; p = q; q = &i; cout << *p <<endl; cout << i <<endl; cout << x << endl; cout << *q << endl;

int *p, *q, *r, *s; int a, b, c, d[10]; p = &a; q

int *p, *q, *r, *s; int a, b, c, d[10]; p = &a; q = &b; *q = 98; *p = 76; q = p; cout <<*p << endl; cout << *q << endl; r = &d[0]; //note this is the same as saying r=d, which is also valid for (int i =0; i < 10; i++) r[i] = i; p = r; ++p; s= p; ++s; cout << *r << endl; cout << *q << endl; cout << *p <<endl; cout << *s <<endl;

Dynamic Allocation Using the new command: int *p 1 = new int; int *p

Dynamic Allocation Using the new command: int *p 1 = new int; int *p 2 = new double[1000]; for (i = 0; i < 1000; i++) p 2[i] = 2*i; delete p 1; delete [] p 2;

int *p, *q, *r, *s; p = new int; *p = 76; cout <<*p

int *p, *q, *r, *s; p = new int; *p = 76; cout <<*p << endl; r = new int [10]; //note this is the same as saying r=d, which is also valid for (int i =0; i < 10; i++) r[i] = i; q = r; ++q; s= q; ++s; cout << *r << endl; cout << *q << endl; cout << *p <<endl; cout << *s <<endl;

Memory Leak int *p 1 = new int; int *p 2 = new double[1000];

Memory Leak int *p 1 = new int; int *p 2 = new double[1000]; for (i = 0; i < 1000; i++) p 2[i] = 2*i; p 2 = p 1; //NOW THE ARRAY IS LOST delete p 1; delete [] p 2;

Array Resizing

Array Resizing

5. 12. 1 Fundamentals of Characters and Strings • Character constant – Integer value

5. 12. 1 Fundamentals of Characters and Strings • Character constant – Integer value represented as character in single quotes – 'z' is integer value of z • 122 in ASCII • String – Series of characters treated as single unit – Can include letters, digits, special characters +, -, *. . . – String literal (string constants) • Enclosed in double quotes, for example: "I like C++" – Array of characters, ends with null character '' – String is constant pointer • Pointer to string’s first character – Like arrays

5. 12. 1 Fundamentals of Characters and Strings • String assignment – Character array

5. 12. 1 Fundamentals of Characters and Strings • String assignment – Character array • char color[] = "blue"; – Creates 5 element char array color • last element is '' – Variable of type char * • char *color. Ptr = "blue"; – Creates pointer color. Ptr to letter b in string “blue” • “blue” somewhere in memory – Alternative for character array • char color[] = { ‘b’, ‘l’, ‘u’, ‘e’, ‘’ };

5. 12. 1 Fundamentals of Characters and Strings • Reading strings – Assign input

5. 12. 1 Fundamentals of Characters and Strings • Reading strings – Assign input to character array word[ 20 ] cin >> word • Reads characters until whitespace or EOF • String could exceed array size cin >> setw( 20 ) >> word; • Reads 19 characters (space reserved for '')

5. 12. 1 Fundamentals of Characters and Strings • cin. getline – Read line

5. 12. 1 Fundamentals of Characters and Strings • cin. getline – Read line of text – cin. getline( array, size, delimiter ); – Copies input into specified array until either • One less than size is reached • delimiter character is input – Example char sentence[ 80 ]; cin. getline( sentence, 80, 'n' );

5. 12. 2 String Manipulation Functions of the String-handling Library • String handling library

5. 12. 2 String Manipulation Functions of the String-handling Library • String handling library <cstring> provides functions to – – Manipulate string data Compare strings Search strings for characters and other strings Tokenize strings (separate strings into logical pieces)

5. 12. 2 String Manipulation Functions of the String-handling Library char *strcpy( char *s

5. 12. 2 String Manipulation Functions of the String-handling Library char *strcpy( char *s 1, const char *s 2 ); Copies the string s 2 into the character array s 1. The value of s 1 is returned. char *strncpy( char *s 1, const char *s 2, size_t n ); Copies at most n characters of the string s 2 into the character array s 1. The value of s 1 is returned. char *strcat( char *s 1, const char *s 2 ); Appends the string s 2 to the string s 1. The first character of s 2 overwrites the terminating null character of s 1. The value of s 1 is returned. char *strncat( char *s 1, const char *s 2, size_t n ); Appends at most n characters of string s 2 to string s 1. The first character of s 2 overwrites the terminating null character of s 1. The value of s 1 is returned. int strcmp( const char *s 1, const char *s 2 ); Compares the string s 1 with the string s 2. The function returns a value of zero, less than zero or greater than zero if s 1 is equal to, less than or greater than s 2, respectively.

5. 12. 2 String Manipulation Functions of the String-handling Library int strncmp( const char

5. 12. 2 String Manipulation Functions of the String-handling Library int strncmp( const char *s 1, const char *s 2, size_t n ); Compares up to n characters of the string s 1 with the string s 2. The function returns zero, less than zero or greater than zero if s 1 is equal to, less than or greater than s 2, respectively. char *strtok( char *s 1, const char *s 2 ); A sequence of calls to strtok breaks string s 1 into “tokens”—logical pieces such as words in a line of text—delimited by characters contained in string s 2. The first call contains s 1 as the first argument, and subsequent calls to continue tokenizing the same string contain NULL as the first argument. A pointer to the current to ken is returned by each call. If there are no more tokens when the function is called, NULL is returned. size_t strlen( const char *s ); Determines the length of string s. The number of characters preceding the terminating null character is returned.

5. 12. 2 String Manipulation Functions of the String-handling Library • Copying strings –

5. 12. 2 String Manipulation Functions of the String-handling Library • Copying strings – char *strcpy( char *s 1, const char *s 2 ) • Copies second argument into first argument – First argument must be large enough to store string and terminating null character – char *strncpy( char *s 1, const char *s 2, size_t n ) • Specifies number of characters to be copied from string into array • Does not necessarily copy terminating null character

1 2 3 // Fig. 5. 28: fig 05_28. cpp // Using strcpy and

1 2 3 // Fig. 5. 28: fig 05_28. cpp // Using strcpy and strncpy. #include <iostream> 4 5 6 using std: : cout; using std: : endl; 7 8 #include <cstring> 9 10 11 12 13 14 int main() { char x[] = "Happy Birthday to You"; Copy entire string char y[ 25 ]; into array y. char z[ 15 ]; 15 16 17 18 19 20 21 22 23 24 25 strcpy( y, x ); <cstring> contains prototypes for strcpy and strncpy. // prototypes for strcpy and strncpy in array x // copy contents of x into y cout << "The string in array x is: " << x 14 characters << "n. The string in array y is: " Copy << y first << 'n'; of array x into array Append terminating nully. Note that // copy first 14 characters of x into zthis does not write terminating character. strncpy( z, x, 14 ); // does not copy null character. z[ 14 ] = ''; // append '' to z's contents cout << "The string in array z is: " << z << endl; fig 05_28. cpp (1 of 2)

26 27 28 29 return 0; // indicates successful termination } // end main

26 27 28 29 return 0; // indicates successful termination } // end main The string in array x is: Happy Birthday to You The string in array y is: Happy Birthday to You The string in array z is: Happy Birthday String to copy. Copied string using strcpy. Copied first 14 fig 05_28. cpp characters (2 of 2) using strncpy. fig 05_28. cpp output (1 of 1)

5. 12. 2 String Manipulation Functions of the String-handling Library • Concatenating strings –

5. 12. 2 String Manipulation Functions of the String-handling Library • Concatenating strings – char *strcat( char *s 1, const char *s 2 ) • Appends second argument to first argument • First character of second argument replaces null character terminating first argument • Ensure first argument large enough to store concatenated result and null character – char *strncat( char *s 1, const char *s 2, size_t n ) • Appends specified number of characters from second argument to first argument • Appends terminating null character to result

1 2 3 // Fig. 5. 29: fig 05_29. cpp // Using strcat and

1 2 3 // Fig. 5. 29: fig 05_29. cpp // Using strcat and strncat. #include <iostream> 4 5 6 using std: : cout; using std: : endl; 7 8 #include <cstring> 9 10 11 12 13 14 int main() { char s 1[ 20 ] = "Happy "; char s 2[] = "New Year "; char s 3[ 40 ] = ""; <cstring> contains prototypes for strcat and strncat. // prototypes for strcat and strncat Append s 2 to s 1. 15 16 cout << "s 1 = " << s 1 << "ns 2 = " << s 2; 17 18 strcat( s 1, s 2 ); 19 20 21 cout << "nn. After strcat(s 1, s 2): ns 1 = " << s 1 Append first 6 characters << "ns 2 = " << s 2; 22 23 24 // concatenate first 6 characters of s 1 to s 3 strncat( s 3, s 1, 6 ); // places '' after last character 25 // concatenate s 2 to s 1 of s 1 to s 3. fig 05_29. cpp (1 of 2)

26 27 cout << "nn. After strncat(s 3, s 1, 6): ns 1 =

26 27 cout << "nn. After strncat(s 3, s 1, 6): ns 1 = " << s 1 Append s 1 to s 3. << "ns 3 = " << s 3; 28 29 30 31 strcat( s 3, s 1 ); // concatenate s 1 to s 3 cout << "nn. After strcat(s 3, s 1): ns 1 = " << s 1 << "ns 3 = " << s 3 << endl; fig 05_29. cpp (2 of 2) 32 33 return 0; fig 05_29. cpp output (1 of 1) 34 35 // indicates successful termination } // end main s 1 = Happy s 2 = New Year After strcat(s 1, s 2): s 1 = Happy New Year s 2 = New Year After strncat(s 3, s 1, 6): s 1 = Happy New Year s 3 = Happy After strcat(s 3, s 1): s 1 = Happy New Year s 3 = Happy New Year

5. 12. 2 String Manipulation Functions of the String-handling Library • Comparing strings –

5. 12. 2 String Manipulation Functions of the String-handling Library • Comparing strings – Characters represented as numeric codes • Strings compared using numeric codes – Character codes / character sets • ASCII – “American Standard Code for Information Interchage” • EBCDIC – “Extended Binary Coded Decimal Interchange Code”

5. 12. 2 String Manipulation Functions of the String-handling Library • Comparing strings –

5. 12. 2 String Manipulation Functions of the String-handling Library • Comparing strings – int strcmp( const char *s 1, const char *s 2 ) • Compares character by character • Returns – Zero if strings equal – Negative value if first string less than second string – Positive value if first string greater than second string – int strncmp( const char *s 1, const char *s 2, size_t n ) • Compares up to specified number of characters • Stops comparing if reaches null character in one of arguments

1 2 3 // Fig. 5. 30: fig 05_30. cpp // Using strcmp and

1 2 3 // Fig. 5. 30: fig 05_30. cpp // Using strcmp and strncmp. #include <iostream> 4 5 6 using std: : cout; using std: : endl; 7 8 #include <iomanip> 9 10 using std: : setw; 11 12 #include <cstring> 13 14 15 16 17 18 19 20 21 22 23 24 25 fig 05_30. cpp (1 of 2) <cstring> contains prototypes for strcmp and strncmp. // prototypes for strcmp and strncmp int main() { char *s 1 = "Happy New Year"; char *s 2 = "Happy New Year"; char *s 3 = "Happy Holidays"; cout << << << "s 1 = " << s 1 << "ns 2 = " << s 2 Compare s 1 "ns 3 = " << s 3 << "nnstrcmp(s 1, s 2) = " setw( 2 ) << strcmp( s 1, s 2 ) "nstrcmp(s 1, s 3) = " << setw( 2 ) strcmp( s 1, s 3 ) << "nstrcmp(s 3, s 1) = " setw( 2 ) << strcmp( s 3, s 1 ); Compare s 1 and s 2. and s 3. Compare s 3 and s 1.

Compare up to 6 characters of Compare "nnstrncmp(s 1, s 3, 6) = "

Compare up to 6 characters of Compare "nnstrncmp(s 1, s 3, 6) = " <<s 1 setw( 2 ) up to 7 characters of and s 3. s 1 and s 3. strncmp( s 1, s 3, 6 ) << "nstrncmp(s 1, s 3, 7) = " Compare up to 7 characters of setw( 2 ) << strncmp( s 1, s 3, 7 ) fig 05_30. cpp s 3 and s 1. "nstrncmp(s 3, s 1, 7) = " (2 of 2) setw( 2 ) << strncmp( s 3, s 1, 7 ) << endl; 26 27 28 29 30 31 cout << << << 32 33 return 0; 34 35 // indicates successful termination } // end main s 1 = Happy New Year s 2 = Happy New Year s 3 = Happy Holidays strcmp(s 1, s 2) = 0 strcmp(s 1, s 3) = 1 strcmp(s 3, s 1) = -1 strncmp(s 1, s 3, 6) = 0 strncmp(s 1, s 3, 7) = 1 strncmp(s 3, s 1, 7) = -1 fig 05_30. cpp output (1 of 1)

5. 12. 2 String Manipulation Functions of the String-handling Library • Tokenizing – Breaking

5. 12. 2 String Manipulation Functions of the String-handling Library • Tokenizing – Breaking strings into tokens, separated by delimiting characters – Tokens usually logical units, such as words (separated by spaces) – "This is my string" has 4 word tokens (separated by spaces) – char *strtok( char *s 1, const char *s 2 ) • Multiple calls required – First call contains two arguments, string to be tokenized and string containing delimiting characters • Finds next delimiting character and replaces with null character – Subsequent calls continue tokenizing • Call with first argument NULL

1 2 3 // Fig. 5. 31: fig 05_31. cpp // Using strtok. #include

1 2 3 // Fig. 5. 31: fig 05_31. cpp // Using strtok. #include <iostream> 4 5 6 using std: : cout; using std: : endl; 7 8 #include <cstring> 9 10 11 12 13 int main() { char sentence[] = "This is a sentence with 7 tokens" ; char *token. Ptr; <cstring> contains prototype for strtok. // prototype for strtok 14 15 16 cout << "The string to be tokenized is: n" << sentence call to strtok begins << "nn. The tokens are: nn"First ; 17 18 19 // begin tokenization of sentence token. Ptr = strtok( sentence, " " ); 20 tokenization. fig 05_31. cpp (1 of 2)

21 22 23 24 // continue tokenizing sentence until token. Ptr becomes NULL while

21 22 23 24 // continue tokenizing sentence until token. Ptr becomes NULL while ( token. Ptr != NULL ) { cout << token. Ptr << 'n'; token. Ptr = strtok( NULL, " " ); // get next token 25 26 } // end while 27 28 cout << "n. After strtok, sentence = " << sentence << endl; 29 30 return 0; 31 32 } // end main // indicates successful Subsequent calls to strtok with NULL as first argument to indicate continuation. termination fig 05_31. cpp (2 of 2)

The string to be tokenized is: This is a sentence with 7 tokens The

The string to be tokenized is: This is a sentence with 7 tokens The tokens are: This is a sentence with 7 tokens After strtok, sentence = This fig 05_31. cpp output (1 of 1)

5. 12. 2 String Manipulation Functions of the String-handling Library • Determining string lengths

5. 12. 2 String Manipulation Functions of the String-handling Library • Determining string lengths – size_t strlen( const char *s ) • Returns number of characters in string – Terminating null character not included in length

1 2 3 // Fig. 5. 32: fig 05_32. cpp // Using strlen. #include

1 2 3 // Fig. 5. 32: fig 05_32. cpp // Using strlen. #include <iostream> 4 5 6 using std: : cout; using std: : endl; 7 8 #include <cstring> 9 10 11 12 13 14 int main() { char *string 1 = "abcdefghijklmnopqrstuvwxyz" ; char *string 2 = "four"; char *string 3 = "Boston"; 15 16 17 18 19 20 21 cout << << << 22 23 return 0; 24 25 <cstring> contains prototype for strlen. // prototype for strlen "The length of "" << string 1 "" is " << strlen( string 1 ) "n. The length of "" << string 2 "" is " << strlen( string 2 ) "n. The length of "" << string 3 "" is " << strlen( string 3 ) << endl; } // end main fig 05_32. cpp (1 of 1) // indicates successful termination Using strlen to determine length of strings.

The length of "abcdefghijklmnopqrstuvwxyz" is 26 The length of "four" is 4 The length

The length of "abcdefghijklmnopqrstuvwxyz" is 26 The length of "four" is 4 The length of "Boston" is 6 fig 05_32. cpp output (1 of 1)

Review Pointers and Strings : What does the following code do? void POKEMON(char *PIKACHU,

Review Pointers and Strings : What does the following code do? void POKEMON(char *PIKACHU, char *ASH) { while (*PIKACHU++ == *ASH++) ; return; } IMPLEMENT IT!