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.
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...
Get Answers For Free
Most questions answered within 1 hours.