Reputation: 9
I'm currently trying to copy one array to another (values 200 - 299 to be specific) while dereferencing pointers.
*point = &array2[100]; //points to location 100 in array2, which holds numbers 100-300
Couldn't I just use a for loop to start where the pointer starts, and then set both arrays equal to each other?
for(i = *point; i < 300; i++){
array2 = array;
}
It says to dereference my pointer, so I'd use something like *(point + a number), but I'm not exactly sure what to do. An example or link to an example would be greatly appreciated
Upvotes: 0
Views: 430
Reputation: 6125
You want something like this:
for (int *p = array1 + 200, *q = array2 + 200; p < array1 + 300; ++p, ++q)
{
*q = *p;
}
Upvotes: 2