Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

each ofits n Proto ii-its parameters. True or false? st specify the name of a fu

ID: 3701605 • Letter: E

Question

each ofits n Proto ii-its parameters. True or false? st specify the name of a function and the name and type of specify the ti rom control return from a void function? where does Match the following terms with the definition void function? a. Argument b. Parameter c. Function call d. Function prototype e. Function definition f. Local variable g. Value parameter h. Reference parameter belovw A function declaration without a body. i. A parameter that receives a copy of the argument's value ii. A variable declared in a function heading iv. A function declaration with a body. A variable or expression listed in a call to a function. v. vi. A statement that transfers control to a function. vii. A parameter that receives the location of the argument. vii. A variable declared within a block are reference parameters? void ExamPrep (string& name, int age, float& salary, char level) 5. In the following function heading, which paramete rs are value parameters and which 6. If a function has six parameters, how many arguments must appear in a callto the 7. What happens if a function assigns a new value to a value parameter? What happens 8. What's wrong with this function prototype? function? if it assigns a new value to a reference parameter? void ExamPrep (phone& int, name string, age& int) nd C++ wi guments can appear in any order as long as they have the correct types a igure out the correspondence. True or false?

Explanation / Answer

2. A function prototype must specify the name of a function and the name and type of each of its parameters. True or false?

Sol) True, Every function prototype must specify the name of function and if it contains parameters that should be specify which type of parameters, For Example,

1. void show();

2. int sum(int,int);

3. int sum(float,int);

3) When and to where does control return from a void function?

Sol) in void function they are not suppposed to return values. But, it is not completely. sometimes we can surely return from void functions. For Example,

a) void show()

{

cout<<"Welcome";

return; //write return in void

}

int main()

{

show();

return 0;

}

output: Welcome

b) void show()

{

cout<<"Welcome";

}

void resultShow()

{

return show(); // returning void function

}

int main()

{

resultShow(); // calling void function

return 0;

}

output: Welcome

4) Match the following terms with the definitions given below.

Sol)

a. Argument - A variable or expression listed in a call to a function

b. Parameter - A variable declared in a function heading

c. Function call - A statement that transfers control to a function

d. Function prototype - A function declaration without a body

e. Functin definintion - A function declaration with a body

f. Local variable - A variable declared within a block

g. Value parameter - A parameter that receives a copy of the argument's value

h. Reference parameter - A parameter that receives the location of the arugment

5) In the following function heading, which parameters are value parameters and which are reference parameters?

void ExamPrep (string &name, int age, float &salary, char level)

Sol) Value Parameters: int age, char level

Reference Parameters: string &name, float &salary

7) What happens if a function assigns a new value to a value parameter? What happens if it assigns a new value to a reference parameter?

Sol) A function assigns a new value to a value parameter is called pass by value. It means copy in memory of the actual parameters value that is passed in a copy of the contents of the actual parameter. For Example,

  

void swapByVal(int x,int y)

{

int temp=x;

x=y;

temp=temp;

}

int main()

{

int a=5,b=10;

swapByVal(a,b);

cout<<a<<" "<<b; // output 5 10, because pass by value

return 0;

}

If it is assign a new value to a reference parameter is call pass by reference. This mean copy of the address of the actual parameter is stored. This pass by reference changing the parameter passed in the program. For Example

void swapByRef(int &x,int &y)

{

int temp=x;

x=y;

y=temp;

}

int main()

{

int a=5,b=10;

swapByRef(a,b);

cout<<a<<" "<<b; // output 10 5, because pass by reference

return 0;

}

8) What's wrong with this function prototype?

void ExamPrep(phone &int, name string,age &int)

Sol) above parameter should be declared is follows

void ExamPrep(int &phone, string name, int &age)

9) Arguments can appear in any order as long as they have the correct types and C++ will figure out the correspondence. True or false?

Sol) False, Arugments must appear in the same order as the corresponding parameters