how to copy pointer to pointer.

char *name1;               //store the value of DAVE
char *name2;              

if name2 was a array i would have done.


but i dont know how to copy pointer into pointer.

i was thinking some thing like this.

name2 = name1?

also do i need to test malloc for name2?

Recommended Answers

All 2 Replies

A pointer is just a variable, so coping a pointer into a pointer is done just like you showed.

    char *name1; 
    char *name2; 

    name2 = name1;

Now both name2 and name1 point to the same memory area.

By using assignment operator, name2 will now point to the same address of name1. So, No use of malloc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.