Question

Given the following function declaration: int myFunction (int& myValue); Which of the following has a legal...

Given the following function declaration: int myFunction (int& myValue); Which of the following has a legal call to the function?

a.cout << myFunction(2);

b.cout << myFunction (4);

c.cout << myFunction ( var); // var is a variable of type int

d.int result = myFunction(3.5);

e.All of the above.

Homework Answers

Answer #1

Question:
Given the following function declaration: int myFunction (int& myValue); Which of the following has a legal call to the function?

Ans: cout << myFunction ( var); // var is a variable of type int

We can see that the function myFunction has a parameter is a reference of argument(simply we can say it as Address of the variable). So in order to call the function, we need a variable that holds a value. so that It can take the address of the variable, modify the value of the variable using that address.

So It is necessary that the argument should be a variable and specifically for this function it should be an int type because the function is accepting a parameter which is int reference. So all the 3 options which are wrong are:
cout << myFunction(2);
cout << myFunction (4);
int result = myFunction(3.5);

The correct way is to do this:
int var=2;
cout << myFunction (var);

Please find the compiled program of the code as well the output for your reference;

Output:


Hope the answer is clear and Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...

Know the answer?
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
Similar Questions
If and else statements: 1a.) Given the following declaration: int temperature; Write an if statement that...
If and else statements: 1a.) Given the following declaration: int temperature; Write an if statement that prints the message "The number is valid" if the variable temperature is within the range of -50 trough 150 (both values excluded). 1b.) Given the following declarations int x; int y; Write an if statement that assigns 100 to x when y is equal to 0. 1c.) Given the following declaration: int grade; Write an if statement that prints the message "The number is...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a + b) * 2; return result; } int main() {   int val; val = add_and_double(12, 40); return 0; } where the function main() (i.e. the caller) calls the function add_and_double() (i.e. the callee). Which of the following actions are taken when main() calls the function add_and_double()?  Select all that apply. a. Once the callee returns, the caller frees the stack memory for the callee's function...
Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2);...
Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the function call quiz(5)? Answer: The first time, i = 5 which is greater than 1, so the function is called twice with a value of (5/2) = 2. Since 2 > i, the function is called 4 times with a value of 1, and is not called anymore, since...
Given the following function:      int C(int n, int k)                  {              
Given the following function:      int C(int n, int k)                  {                     if (k= =0) return 1;                        else return (C(n-1, k-1) * n)/k;                                       } What type of function is this? Recursive or Iterative. Explain your answer.
The following function compares integers of type int and gives as a result the smaller Number:...
The following function compares integers of type int and gives as a result the smaller Number: int min (int a, int b) { if (a < b) return a; else return b; } Create a template and Convert this function to a template. Before converting this function to a template, display how you would handle var a & b if they held the same value. In other words if a and b are equal, what would you do (how would...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
Given the following function: int bar(int n) {     if( n < 0 )         return...
Given the following function: int bar(int n) {     if( n < 0 )         return -2;     else if (n <= 1)         return 2;     else       return (3 + bar(n-1) + bar(n-2)); } What is returned by bar (4)? Show all the steps
(c programming) Given the function declaration and documentation below, write the function definition. Do not use...
(c programming) Given the function declaration and documentation below, write the function definition. Do not use the standard library function fgetc. /// @brief Reads a character from specified file input stream. /// @param instream A FILE* variable for an input stream to read a character from. /// @return A character of type char from instream. /// @note This function assumes #include <stdio.h> and a working, valid FILE* variable to an input stream. char grabchar(FILE* instream);
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
What does the following variable declaration in C mean, assuming it occurs within a function called...
What does the following variable declaration in C mean, assuming it occurs within a function called my_function() ? static int x = 0 ; x retains its value between calls to my_function() x is a constant and cannot be changed within that function x is a global variable and can be accessed from other functions directly Syntax error, this is not a valid C statement.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT