0

How to copy an array integers to another variable?

for example : int var[]={9}; int someCopy = var[0]; // copy value, assume this is a wrong example int newVar=18; var[0]=newVar; // assign newVar to var[0] how to print someCopy but the value of array var before doesn't change?

17th Jun 2018, 1:45 AM
sherlockholmes
sherlockholmes - avatar
3 Answers
+ 1
To print someCopy, you do : cout<<someCopy;
17th Jun 2018, 8:07 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
Can you explain a little more in detail? As far as I can understand, you want var[0] to be 18(newVar) and someCopy to be 9 (var[0]'s original value), right? Your current assignments do exactly this, and you can print someCopy without worrying about the value of var[0].
17th Jun 2018, 3:19 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
after array var value change by newVar. how to print current value of someCopy if the command to print, made after changing array var?
17th Jun 2018, 7:29 AM
sherlockholmes
sherlockholmes - avatar