Hands-on 5a

Pointers, Arrays

Start code: session5-start.tar.gz

Program referencesVsPointers

  • Download the start code and unpack it in your working area:
$ tar xzvf session5-start.tar.gz
  • Inspect the code in referencesVsPointers.cxx file, compile and run the program.

Arrays

  • Copy the program mailing_list_longest.cxx (developed in session 3) in arrays.cxx and change the usage of std::vector with C-array.

    • Replace the line where we define myVector of std::vector type:
  vector<string> myVector;

with

  string myVector[22];
  • You need then also adapt the rest of the program.

  • Comment on the differences.

  • Set the array size equal to the number of the actual elements (22). Then add a few more elements and rerun the program. Add the same elements to the std::vector in mailing_list_longest.cxx. What’s the difference between these programs now?