Professional Documents
Culture Documents
a. int x, y;
int *p = &x;
int *q = &y;
*p = 35; *q = 98;
*p = *q;
cout << x << “ “ << y << endl;
cout << *p << “ “ << *q << endl;
Answer: 98 98
98 98
b. int x, y;
int *p = &x;
int *q = &y;
x = 35; y =46;
p = q;
*p = 78;
cout << x << “ “ << y << endl;
cout << *p << “ “ << *q << endl;
Answer: 35 78
78 78
Answer: 39 39
Answer: 78 78
int *p = list;
cout << *(list = i) << endl;
cout << list[i] << endl;
cout << *(p+i) << endl;
cout << p[i] << endl;
Answer: 11
11
11
11
Answer: 44 57 10 14 19 25 32 40
g. int j, *p;
p = new int[10];
p[0] = 10;
for (j = 1; j < 10; j++)
p[j] = p[j – 1] + 5;
for (j = 0; j < 10; j++)
cout << p[j] << “ “;
cout << endl;
Answer: 10 15 20 25 30 35 40 45 50 55
Answer: array p: 5 7 11 17 25
array q: 25 17 11 7 5
2. Given the declaration:
int num = 6;
int *p = #
a. p++
b. (*p)++
c. num++
d. (*num)++
Answer: b, c
3. Draw a diagram to show the memory configuration after the following statements are executed:
int i,j;
int *p;
int *q;
p = new int[5];
q= new int[5];
p[0] = 10;