logo

UTK Notes


Clicker Questions - 11-Pointers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  vector <int *> v1;
  vector <int> v2;
  vector <int> *v3;
  int i;
  int *p;

  v3 = &v2;
  while (cin >> i) {
    p = new int;
    *p = i;
    v1.push_back(p);
    v2.push_back(*p);
  }

  for (i = 0; i < v1.size(); i++) *(v1[i]) += 2;
  for (i = 0; i < v2.size(); i++) v2[i] += 10;

  for (i = 0; i < v1.size(); i++) cout << *(v1[i]) << endl;
  for (i = 0; i < v2.size(); i++) cout << v2[i] << endl;
  for (i = 0; i < v3->size(); i++) cout << v3->at(i) << endl;
  return 0;
}

Behold the program to the right. We compile it to the file a.out and then we run it with:


UNIX> echo 30 50 70 | ./a.out

  • Question 1: What is the first line of output?
Answer
32
  • Question 2: What is the second line of output?
Answer
52
  • Question 3: What is the third line of output?
Answer
72
  • Question 4: What is the fourth line of output?
Answer
40
  • Question 5: What is the fifth line of output?
Answer
60
  • Question 6: What is the sixth line of output?
Answer
80
  • Question 7: What is the seventh line of output?
Answer
40
  • Question 8: What is the eighth line of output? Enter a dash if there is no eighth line.
Answer
60
  • Question 9: What is the nine line of output? Enter a dash if there is no ninth line.
Answer
80

No Class Stats, PDF Download