Write a function that copies an array of integers using pointers.
Write a main function to test your functions.
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#define SZ 3
void copy(int src[], int dst[], int sz)
{
int *s = src;
int *d = dst;
int i;
for (i=0; i<sz; i++ )
{
*d = *s;
s++;
d++;
}
}
void main() {
int a[SZ] = { 1, 2, 3};
int b[SZ];
int i;
copy(a,b,SZ);
for ( i=0; i<SZ; i++)
printf("%d ", b[i]);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Calculation of a Polynomial of degree N