Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this:
char * mio;

char * tuo;

tuo = mio;

but is there a way if I want to change only the content of one pointer?

example:

if mio = "ciao";

and tuo = "ciao";

can I change the content of only mio and not tuo?

What I have tried:

I tried to search on internet but I don't find
Posted
Updated 4-Mar-24 23:00pm
v3
Comments
KarstenK 6-Mar-24 3:07am    
your question makes clear that you need some basic tutorials about pointers. Take the time, it will be worth it.

No. If you have two pointers pointing to the same thing, then changes to the thing they point to will be visible to both.

That would be like saying Alice and Bob live in the same house, and I want to demolish Bob's house without touching Alice's house.

You would need to make a copy of the pointed-to thing, change one of the pointers to point to the new copy, then change that copy.
 
Share this answer
 
Comments
CPallini 5-Mar-24 5:56am    
5.
I strongly suggest you to read a good book on the C/C++ programming languages. Also, reading some introductory material on pointers. As an example, for instance C Pointers (With Examples)[^], could be a start.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900