I am trying to pass a 2d array to a function by reference and for some reason it is not giving me a correct output (step 3 in the code below). I am super new to C++ so please be kind :(
Whenever you pass a array into a function, it automatically assumes it is passed by reference. That is what I learned in my new programming class 2 months ago lol.
Thanks Hunter.But in step 3 when I am trying to print out the modified array it is not doing so..
My understanding was By Reference means that it passes the address(not a copy) of the array so when we make changes within the function it would make changes to the original array as well..so confusing :/
You need an assignment statement. Just think how you'd do this with any variable you wanted to add 1 to, it's the same idea. a = a + 1, or a += 1 changes the value in a by adding 1.
To modify elements in the array, you have to modify elements in the array. Normally this is done via some sort of assignment.
For instance if I have an int, i with value 1 and I want to increment it by 2 so that it's value is 3, I might write: i += 2, but if I were to just write, instead: cout << i+2; the number output would be 3, but i would be unchanged. There was no assignment to it.