1- define a second argument (example "int number2 = 9") and a pointer to it 2- define a second function (addByReference) that adds number2 to number - passing both arguments by reference 3- print-out the result (that is in number)
#include <stdio.h>
void cubeByReference( int *nPtr ); // function prototype
int main( void )
{
int number = 5; // initialize number
printf("The original value of number is %d", number );
// pass address of number to cubeByReference
cubeByReference( &number );
printf("\nThe new value of number is %d\n", number );
} // end main
void cubeByReference( int *nPtr )
{
*nPtr = *nPtr* *nPtr* *nPtr;
}
passing argument by reference -
We modify the code above
1- define a second argument (example "int number2 = 9") and a pointer to it
2- define a second function (addByReference) that adds number2 to number - passing both arguments by reference
3- print-out the result (that is in number)
Upload the output and .c code
Trending now
This is a popular solution!
Step by step
Solved in 3 steps