Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy variable without changing original 1

Status
Not open for further replies.

edmund1978

Programmer
Jan 25, 2001
58
0
0
GB
Stuck trying to copy a variable eg. var1 = var2; After a call like this I think that var1 is changed anytime var2 is. I think I need to use pointers but when I tried this, I got the same problem.
 
Without knowing the variable types it is impossible to answer or comment.

-pete
 
if you have something like below, it should work for you.

int main()
{
int num1 = 3;
int num2 = 5;

num1 = num2; // num1 == 5 && num2 == 5

return 0;
}

the other thing is, what kind of variables are they? Are they ints? floats? depending on what type of variable you have can affect how you should be assigning the value of one to the other...

Hope this helps

thiefmaster
 
Thanks for the help, sorted it now. My problem wasn't what I thought, I had some values as int copying from float. This was giving weird results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top