Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!