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
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...
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.
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
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?
(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);
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.
Please complete the following function getMax, which accepts three integer parameters (int p, int q, int...
Please complete the following function getMax, which accepts three integer parameters (int p, int q, int r), and must return the maximum of those 3 integers received to the caller. int getMax(int p, int q, int r) // returns the max of 3 integers { // begin getMax() // Enter your code here:::::::::::::::::::::::::::::      } // end getMax() void main( ) // To test function getMax( ) { cout << "Data: 9 18 4 , Max = " << getMax(9,...
Write a C function to compute the following output (int) based on two input (int) variables:...
Write a C function to compute the following output (int) based on two input (int) variables: output = a*a + b*b - 2*a*b If the value of output is '0', then return -1 instead. Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case. a = 3, b = 4 a = 1, b = 1 a = -2 b = 3 a = -4 b =...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...