user437777
user437777

Reputation: 1519

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

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];
Ptr2[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

Upvotes: 2

Views: 6065

Answers (1)

vanza
vanza

Reputation: 9903

memcpy is your friend.

Upvotes: 3

Related Questions