Question: HW4: 1. If an array is passed as an argument to a function which is expecting an array, and if the function changes some or
HW4: 1. If an array is passed as an argument to a function which is expecting an array, and if the function changes some or all the contents of the array, will the passed in arrays contents will get changed or not? Like below. Also, what will the below print statements print? Your main function looks like this: int arrayToPassToAnyFunction[ ] = { 1, 2, 3 }; func1 ( arrayToPassToAnyFunction ); print ( arrayToPassToAnyFunction ); and func1 is implemented as: void func1 ( int anyPassedInArray[ ] ) { anyPassedInArray[ 0 ] = anyPassedInArray[ 0 ] + 5; anyPassedInArray[ 2 ] = anyPassedInArray[ 2 ] + 6; print ( anyPassedInArray ); } 2. If some/all 'contents' of the array (the integer variables here) are passed as an argument to a function which is expecting integer variables, instead of the whole array, and if the function changes the contents of those passed in integer variable(s), will the array's contents after the call change or not? Like below. Also, what will the below print statements print? Your main function looks like this: int arrayToPassToAnyFunction[ ] = { 1, 2, 3 }; func1 ( arrayToPassToAnyFunction[ 0 ] , arrayToPassToAnyFunction[ 2 ] ); print ( arrayToPassToAnyFunction ); and func1 is implemented as: void func1 ( int anyPassedInInteger1, int anyPassedInInteger2 ) { anyPassedInInteger1 = anyPassedInInteger1 + 5; anyPassedInInteger2 = anyPassedInInteger2 + 6; print ( anyPassedInInteger1 ); print ( anyPassedInInteger2 ); } 3. What will the below print statements print, and why? Your main function looks like this: int arrayToPassToAnyFunction[ ] = { 1, 2, 3 }; func1 ( arrayToPassToAnyFunction ); print ( arrayToPassToAnyFunction ); and func1 is implemented as: void func1 ( int anyPassedInArray[ ] ) { int variable1 = 0; int variable2 = 0; variable1 = anyPassedInArray[ 0 ] + 5; variable2 = anyPassedInArray[ 2 ] + 6; print( variable1 ); print( variable2 ); } 4. What will the below print statements print, and why? Your main function looks like this: int arrayToPassToAnyFunction[ ] = { 1, 2, 3 }; func1 ( arrayToPassToAnyFunction ); print ( arrayToPassToAnyFunction ); and func1 is implemented as: void func1 ( int anyPassedInArray[ ] ) { print( anyPassedInArray ); anyPassedInArray = {5, 6, 7}; print( anyPassedInArray ); }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
