0

how to copy pointer to pointer.

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

if name2 was a array i would have done.

strcpy(name2,name1);

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?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Shardendu
1

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.