Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started