Beruflich Dokumente
Kultur Dokumente
CSPP50101-1
due Monday Sept. 2
General instructions: anywhere I say "write a function that ...", this
implies that you should include a main which gets data from argv and
calls the function.
All file input should take place through stdin and redirection. If you wish
to support direct file reads in addition, that's good but not required.
1. Rewrite the following function using pointer arithmetic in place of
array subscripting, as we discussed at length in class. As a reminder,
p[i] = *(p+i) by definition. You will get no credit if the new
function (ie the one you write) does not give the same results as the
original function. It is up to you to test this. Name your new function
new_mystery.
void mystery( int a[], int n ){
int i, tmp1, tmp2;
tmp1 = a[n-1];
for ( i=0; i<n-1; i=i+2 ){
tmp2 = a[i];
a[i] = tmp1;
tmp1 = a[i+1];
a[i+1] = tmp2;
}
}
Explain in words what this function does.
e) int i,j;
int* iptr, jptr;
iptr = &i;
jptr = &j;
b) char *p;
*p = 3;
f) char *p;
strcpy(p, "hello world");
c) char p;
char *pptr = &p;
*(pptr+2) = 'c';
g) int *fptr;
fptr = 1;
h) char *f[100];
f[0] = getchar();