How can Can I copy the contents of one variable into another???
Expand Post »
Hi...
I am a bit new to programming, and I'm trying to learn C++. I was wondering if there was a way to copy the contents of one variable into another... So that, for example:
int x=5;
int y;
(Some fancy code here involving x and y);
(y=5 but it is not related at all to x. If x is assigned a value of 10438478234 later in the code, y will still equal 5)
The reason is that if I use variable assingment or pointers, and x changes, then so will y... If you please, list a code or method in order to achieve this data transfer
Re: How can Can I copy the contents of one variable into another???
It does work like that?? But what about the "x=y" part, followed by "x=10"???? Doesn't that say "x has same value as y, and x is now 10" Doesn't that mean that y will also be 10?? (Please excuse my noobish questions, I'm just staring with this thing!!!)
Re: How can Can I copy the contents of one variable into another???
er...
look at it this way
when there is a = sign remember that it is an assignment operator not an "equal" sign
anything on the left is assigned to what is on the right
Quote ...
But what about the "x=y" part, followed by "x=10"???? Doesn't that say "x has same value as y, and x is now 10" Doesn't that mean that y will also be 10??
Looks like you read it wrong.
the only variable assignment he made was y = x
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.