Question

For each of the following function calls, please write if the parameter is passed by value...

For each of the following function calls, please write if the parameter is passed by value or passed by reference to a hypothetical function 'myFunc'. You should briefly explain why to get full credit.

Q7.1

3 Points

int num = 5; myFunc(num);

Q7.2

3 Points

int num = 5; myFunc(&num);

Q7.3

3 Points

int num[] = {5}; myFunc(num);

Q7.4

3 Points

int num[] = {5,6,7,8,9}; myFunc(num);

Q7.5

3 Points

char name[6] = "Hello"; myFunc(name);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER

Q7.1

int num = 5;

myFunc(num);

Ans -)

It is pass by value not reference in this we just pass num which is recieved by another variable in the myFunc() which is a copy of num value.

Q7.2

int num = 5;

myFunc(&num);

Ans -)

It is passed by reference.

Because in parameter passing &num is passed which means the address of num variable is passed. So it is not a copy any changes in that address value also reflect in the num.

Q7.3

int num[] = {5};

myFunc(num);

Ans -)

It is passed by refrence.

Whenever we pass the array to the function it is pass by refrence.

When we pass the array then the refrence of array is passed so changes in different array reflects the changes in the original array also.

Q7.4

int num[] = {5,6,7,8,9};

myFunc(num);

Ans -)

It is also a passed by refrence.

Whenever we pass the array to the function it is pass by refrence.

When we pass the array then the refrence of array is passed so changes in different array reflects the changes in the original array also.

Q7.5

char name[6] = "Hello";

myFunc(name);

Ans -)

It is also a passed by reference.

Because value passed with array is pass by reference.

If any changes in the passed array will also reflect in the original array.

Add a comment
Know the answer?
Add Answer to:
For each of the following function calls, please write if the parameter is passed by value...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • _28. Using the following function prototype which statement about the argument passed to parameter Als true....

    _28. Using the following function prototype which statement about the argument passed to parameter Als true. void F(const int A[], int Cnt): A. The argument is modified when changes are made to parameter A in function F. B. The argument passed to parameter A must always have the same number of elements, every time function Fis invoked. C. Changes can not be made to parameter A in function F. D. Every element of the argument passed to parameter A must...

  • LANGUAGE: C Below we are dissecting the structure of atoi and its pitfalls using invalid calls...

    LANGUAGE: C Below we are dissecting the structure of atoi and its pitfalls using invalid calls Below are invalid calls to atoi Please answer the following questions just in the context/frame provided based on your understanding of how this function works. Yes there are warnings when you run this code, but I am just trying to conceptually understand why these calls are invalid. We already know they are invalid. a) "&num" returns 2, I am aware that 'num' -'0' has...

  • COSC 112 Test #3 Spring 2019 20. It is not necessary to specify the parameter name...

    COSC 112 Test #3 Spring 2019 20. It is not necessary to specify the parameter name in the parameter list of a function prototype even 21. Which of following is not a situation when reference parameters are useful? though there is a default parameter. (True/False) a. When you don't want to have side effects b. When you need to change the actual parameter c. When you need to return more than one value d. When you want to save memory...

  • 3. [30pts] Determine the following information about a value passed in as a parameter. (a) Is...

    3. [30pts] Determine the following information about a value passed in as a parameter. (a) Is the value a multiple of 7, 11 or 13? (b) The sign of the value (-1 if it is negative, 0 if it is 0 and 1 if the value is positive). You should write a function with three type int parameters, one input parameter (the value) and two other output parameters. The function should send back the answers to the two questions above...

  • Explain what each of the following instructions does. ifstream some_data some_data.open("my_stufr.dat"); ofstream more_data. more_data.open("other_sluff.dat"); Given the...

    Explain what each of the following instructions does. ifstream some_data some_data.open("my_stufr.dat"); ofstream more_data. more_data.open("other_sluff.dat"); Given the instructions in the previous problem, write each of the follow pieces of a program. Write a loop that will read doubles from the input file. Each number will be put into a variable named the_number and then added to a variable named the_total. When the end of file is reached, print the number using cout. Write a loop that will read strings from cin...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Code in C++: Please help me fix the error in function: void write_account(); //function to write...

    Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT