+ 1

What is variable memory address used for in C++

I’ve just learned about memory address in my C++ tutorial and I want to know the uses

4th Mar 2018, 8:00 PM
Christian
1 Resposta
+ 2
Imagine you want to pass a variable by reference. You can do it with the help of the variable's memory address e.g.: Add(int* numb) { *numb += 100; //adds 100 to the variable } int main(){ int i = 0; Add(&i); cout << i << endl; //it's 100 return 0; } As you can see it adds 100 to i and since it's passed by reference type it affects the variable in the main function too.
4th Mar 2018, 8:31 PM
Kevin Eldurson
Kevin Eldurson - avatar