logo

UTK Notes


Clicker Questions - 10-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
29
30
31
32
33
34
35
36
#include <iostream>
#include <vector>
using namespace std;

int main()                    /* Line  1 */
{                             /* Line  2 */
  vector <int *> iv;          /* Line  3 */
  vector <int> jv;            /* Line  4 */
  int *ip, *jp, *kp;          /* Line  5 */
                              /* Line  6 */
  ip = new int;               /* Line  7 */
  jp = new int;               /* Line  8 */
  kp = new int;               /* Line  9 */
                              /* Line 10 */
  *ip = 22;                   /* Line 11 */
  *jp = 33;                   /* Line 12 */
  *kp = 44;                   /* Line 13 */
                              /* Line 14 */
  iv.push_back(ip);           /* Line 15 */
  iv.push_back(jp);           /* Line 16 */
                              /* Line 17 */
  jv.push_back(*(iv[1]));     /* Line 18 */
  jv.push_back(*(iv[0]));     /* Line 19 */
                              /* Line 20 */
  *(iv[0]) = *kp;             /* Line 21 */
  kp = jp;                    /* Line 22 */
                              /* Line 23 */
  cout << *ip << endl;        /* Line 24 */
  cout << *jp << endl;        /* Line 25 */
  cout << *kp << endl;        /* Line 26 */
  cout << *(iv[0]) << endl;   /* Line 27 */
  cout << *(iv[1]) << endl;   /* Line 28 */
  cout << jv[0] << endl;      /* Line 29 */
  cout << jv[1] << endl;      /* Line 30 */
  return 0;                   /* Line 31 */
}                             /* Line 32 */

Behold the program to the right.

  • Question 1: What is the first line of this program’s output?
Answer
*ip: 44
  • Question 2: What is the second line of this program's output?
Answer
*jp: 33
  • Question 3: What is the third line of this program's output?
Answer
*kp: 33
  • Question 4: What is the fourth line of this program's output?
Answer
*iv[0]: 44
  • Question 5: What is the fifth line of this program's output?
Answer
*iv[1]: 33
  • Question 6: What is the sixth line of this program's output?
Answer
jp[0]: 33
  • Question 7: What is the seventh line of this program's output?
Answer
jp[1]: 22
  • Question 8: On which line does a memory leak occur?
Answer Line 22

No Class Stats, PDF Download