简体   繁体   中英

Dereferencing pointers to make a copy of an array

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

You want something like this:

for (int *p = array1 + 200, *q = array2 + 200; p < array1 + 300; ++p, ++q)
{
    *q = *p;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM