How does that read exactly? I understand what it does by the function name, but I don't understand what *=2; actually means. If someone could give me a quick answer that would be great.
Thanks for the reply oleg. So If I am understanding correctly.
this statement in line 3 reads
m is equal to m times two.
the old value of m is now destroyed forever
old value of m , is being overwritten(namely , the bits of this integer)
don't forget that you are passing the argument of the function by value , so it will make a copy
ex :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int g = 17;
void multiplyByTwo(int m)
{
m*=2;
cout << m ; // 34
}
int main()
{
multiplyByTwo(g);
cout << g; // 17
}
#include <iostream>
usingnamespace std;
void multiplyByTwo(int m)
{
m*=2; // m = m * 2; same result
cout << "g is " << m << " after multiplyByTwo\n";
}
int main()
{
int g = 17;
cout << "integer g starts as " << g << "\n";
multiplyByTwo(g);
return 0;
}