CSCI 159: exam practice questions

These are just meant as a way to get some practice answering exam-style questions with pen/paper. I'd encourage students to attempt them with minimal references to their notes, but for the final exam you will be permitted one double-sided sheet of notes.

There is one question on each side of the page.

After you've attempted the question, a good way to evaluate your answer while also getting additional practice is to coding and compiling/running the answer you came up with.

Question 1: Basic pointers

For each of the cout statements below, show the values of x and y and explain why they have those values.
   int x, y;
   y = 32;
   x = 5;
   int *ptr1;
   int *ptr2;
   ptr1 = &x;
   (*ptr1) = 10;
   x++;
   cout << x << "," << y << endl;
   ptr2 = ptr1;
   ptr1 = &y;
   y = 45;
   cout << x << "," << y << endl;
   (*ptr1) = 99;
   (*ptr2) = (*ptr1) - 5;
   cout << x << "," << y << endl;

Question 2: Arrays, new and delete[]

Write a main routine that does the following in the sequence shown: