# pointer review

Post on 22-Feb-2016

33 views

Category:

## Documents

0 download

Embed Size (px)

DESCRIPTION

Pointer Review. Node { int value; Node * next; Node( int val =-1, Node * n = NULL) {value = val ; next = n;} }. Given a ordered linked list pointed to by head, write the code to insert an element with value x. - PowerPoint PPT Presentation

TRANSCRIPT

Pointer Review

Pointer Review

Node { int value; Node * next; Node( int val =-1, Node * n = NULL) {value = val; next = n;}}

Given a ordered linked list pointed to by head, write the code to insert an element with value x.Node { int value; Node * next; Node( int val =-1, Node * n = NULL) {value = val; next = n;}}

Given a ordered linked list pointed to by head, write the code to delete an element with value x.

What type is a *a **a

What type is a *a **a

Hint: I read the declaration backwards, a is a pointer to a pointer to an int.

When I look at *a, I mentally glue the *atogether and thinkint * (*a)*a is a pointer to an int.Fill in the blanks//find and return the maximum value in an arrayint maxEntry(int* data, int size) { if ( data == NULL || size next = p->next;p->next = NULL;

Show the picture after executingq->next = p->next;q->next->next = p;p->next = NULL;

Show the picture after executingq->next = NULL;delete p;

Show the picture after executingdelete (p->next);

Show the picture after executingq->next = head;delete p;

Show the picture after executingdelete Head;head = q;

Given the following, explain the effect of the following on the contents of ptr and i:int i = 10,;int *ptr = &iint j = 4;*ptr += j;

Given the following declarationsint a[] = {5, 15, 34, 54, 14, 2, 52, 72};int *p = &a;int *q = &a;What is the value of *(p+3)?

1424Given the following declarationsint a[] = {5, 15, 34, 54, 14, 2, 52, 72};int *p = &a;int *q = &a;What is the value of *(q-3)?

3425Given the following declarationsint a[] = {5, 15, 34, 54, 14, 2, 52, 72};int *p = &a;int *q = &a;What is the value of q p ?

426Given the following declarationsint a[] = {5, 15, 34, 54, 14, 2, 52, 72};int *p = &a;int *q = &a;Is the condition p < q true or false?

Given the following declarationsint a[] = {5, 15, 34, 54, 14, 2, 52, 72};int *p = &a;int *q = &a;Is the condition *p < *q true or false?

false28

Recommended