5. Pointers and References
Activity 5: Using Pointers and References to Manipulate an Array of Strings
Solution:
- Enter the skeleton
main()
function:#include <iostream> using namespace std; int main() { return 0; }
- Above
main()
, create an array of strings:char const* array[26] { "alpha", "bravo", "charlie", "delta", "echo" };
The array must be 26 elements long or the program might crash for certain valid arguments.
- Enter the skeleton of the
printarray()
function. Define the arguments. Since we are printing an array of literal strings, the pointers are of typechar const**
. Thecount
argument is anint&
. Define the return type, which is specified asint
in the assignment:int printarray(char const** begin, char const** end, int& count) { return 1; }
- Clear
count
:count = 0;
- Enter code...