Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. The code in Listing 6-1 shows a program with a function named passRef. In the main function, the reference (address) of the variables numi
4. The code in Listing 6-1 shows a program with a function named passRef. In the main function, the reference (address) of the variables numi and num2 are passed to function passRef. This is called pass-by-reference. Write and run the code to see the result. #include int passRef( int *x, int *y); int main() { int num1-10, num2-100; printf(" Num1 = % Num2= %d ", numi, num2); passRef (&num1,&num2); printf(" Num1 - %d Num2 = %d ", numi, num2); } int passRef (int *x, int *y) { *X= 20; *y= 200; } Listing 6-1: Function (pass-by-reference) Based on the program code in Listing 6-1, write a new program to declare and initialize two integers num1=10 and num2=100. Using a printf statement, display the values of numi and num2. From the main function, pass the two variables num1 and num2 to a function named passValue. The function prototype can be written as int passValue(int numi, int num2). In function passValue, assign 20 to num1 and 2000 to num2. The function does not return any value. In the main function, once again, write a printf statement to print the values of numi and num2. Compare the result with the one obtained from Listing 6-1 above
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