开发者

Copying 1 Array of Pointer to 2nd Array of Pointer in C

开发者 https://www.devze.com 2023-01-25 02:06 出处:网络
I have two array of pointers and I want to copy one to other Int32 *Ptr1[2]; Int32 *Ptr2[2]; Int32 a,b; Ptr1[0]=&a;

I have two array of pointers and I want to copy one to other

Int32 *Ptr1[2];
Int32 *Ptr2[2];
Int32 a,b;

Ptr1[0]=&a;
Ptr1[1]=&b;

I want Ptr2 to hold Ptr1[0] and Ptr2[1];

Ptr2[0]=Ptr1[0];
Pt开发者_如何学Cr2[0]=Ptr1[1];

Is there any other way, because If the array is huge, copying will be a problem

I did the following

Ptr2=Ptr1;

This copies the address of Ptr1 to Ptr2 but its elements are not copied..

Please help


memcpy is your friend.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号