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 :

``````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?

Edited by khelkely: for Q2, in before i'd answer *p = 13

2
Contributors
1
15
Views
4 Years
Discussion Span
Last Post by tinstaafl

You might need to brush up on your instructional material a bit more. If necessary, here's a couple of fairly good explanations of how pointers and references work.Click Here Click Here

``````#1 - p and r are wrong, q is right
#2 - p and q are wrong
#3 - q->value is wrong
``````

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.