Section 18.6 First Look at Modifying Arrays with Functions
Modifying the value of a variable inside a function isn’t quite as easy as it sounds. The techniques that we know of so far cannot accomplish this task (other than via using the return value of a function) as we can see via the
function1()
example below. We’ll learn soon how to do this however!But now look at
function2()
. Given what we learned from function1()
we’d expect the array variable in our main function not to get modified via the attempted change inside function2. See what happens though...