// ex4.cDownload Example 4
//
#include <stdio.h>
#define numitems 50
int main(int argc, char* argv[])
{
int data[numitems];
int *ptr;
for(ptr = data; ptr < &data[numitems]; ptr++)
*ptr = 0;
return 0;
}
Example 5. You might recognise a version of this from this C Programming Problem blog entry as an example of code with errors in it. This is the correct version.
// ex5.cDownload Example 5.
//
#include <stdlib.h>
#define maxitems 1000
typedef int vector[maxitems];
int * addvectors(int * v1,int * v2) {
int index;
int * result = (int *) malloc(sizeof(vector)) ;
int * temp=result;
for (index =0;index < maxitems;index++)
(*temp++)= *v1++ + *v2++;
return result;
}
int main(int argc, char* argv[])
{
vector a,b;
int *c;
int index;
for( index=0; index < maxitems; index++){
a[index]=10+index;
b[index]= index*1000;
}
c= addvectors((int *)a,(int *)b) ;
free(c) ;
return 0;
}
On the Next Page : A complicated example. Slightly trimmed to fit!

