Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions