Tutorial Exercises 5

Tue, 27 Oct 2009 00:00:00 -0300
/tags/C, /tags/cs2023/tutorial

Exercises from Chapter 11,12 of King

1. Given the following declarations

int i;
int *p,*q;

Which of the following assignments are legal

p=i;
*p=&i;
&p=q;
p=&q;
p=*&q;
p=q;
p=*q;
*p=q;
*p=*q;

1. Write the following function

void find_two_largest(int a[], int n, int *largest, int *second_largest);

1. What will be the contents of array a after the following code is executed?

#define N 10
int a[N] = {1,2,3,4,5,6,7,8,9,10};
int *p=a,*q=a+N-1;
while(p<q){
  int temp=*p;
  *p++=*q;
  *q--=temp;
}