#include #include // Copy the elements of one array into another using pointers // This buggy program still works but but it demonstrates some of // the dangers with using pointers. int main() { int *ip1, *ip2; int i; int a[5] = {1, 3, 4, 5, 6}; int b[5]; // {?, 1, 3, 4, 5}; + 6 (<--out of bounds assignment) // this will be the result after copying // for(i=0; i<5; i++) // This is how we can do it without pointers // b[i] = a[i]; ip1 = &a[0]; ip2 = &b[1]; // *ip2 now points to b[1] and is thus off by one for(i=0; i<5; i++) // copy the array *(ip2+i) = *(ip1+i); for(i=0; i<5; i++) // print the copy printf("%d, ", *(ip2+i) /*b[i]*/); system("pause"); }