CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Oct 2013
Posts
4

## Exercise - Pointer

Q1: Trace the partial of program below:

1. int v = 8, *r, *s;
2. int *p;
3. int q = 100;
4. p = &q;
5. r = p;
6. *p = 20;
7. p = new int;
8. *r = 30;
9. q = v;
10. s = p;
11. *s = 50;

What are the last values of *p, q, *r, v and *s?
*p = 20
q = ?
*r = 30
v = ?
*s = 50

i can't find q and v. But, if q will point whatever v point, so, the value of q is 8 ? am i right ?

Q2 = Given the following codes:
1. int *p , *q , v , nom[5];
2. p = &v;
3. *p = 12;
4. q = p;
5. nom[0] = *q;
6. p = nom;
7. p++;
8. nom[2] = 12;
9. *p = 13;
10. *q = 10;
11. v = 11;
12. *(p+3) = 16;
13. p = &nom[3];
14. *p = 10;
15. p--;

What are the last values of *p, *q, v and nom ?

*p = 10
*q = 10
v = 11
nom = ?

i can't find nom .

Q3 : Given below declaration :
Code:
struct Node
{
int  value;
Node  * next;
};
In the main function, the following codes are given:
1. Node *q, *r;
2. Node *p = new Node; //address of this new Node adalah 10000
3. q = r = NULL;
4. p -> value = 9;
5. p -> next = NULL;
6. q = new Node; //address of this new Node adalah 10050
7. p->next = q;
8. p->next->value = 8;
9. q->next = new Node; //address of this new Node adalah 10100
10. r = q;
11. r-> value = 10;
12. q->next->value = 11;
13. q = q-> next;
14. q -> next = NULL;

What are the last values of p->value and q->value ?

p->value = 9
q->value = NULL

Anyway, is it relevant my answer?
Last edited by khelkely; October 17th, 2013 at 09:57 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•