Learning Objectives: Build functions that return a value Determine when to overl
ID: 3706459 • Letter: L
Question
Learning Objectives:
Build functions that return a value
Determine when to overload functions
Examine value-returning functions, including actual and formal parameters
Explore how to construct and use a value-returning, user-defined function in a program
Construct and use void functions in a program
Discover the difference between value and reference parameters
Explore reference parameters and value-returning functions
Instructions:
Read chapter 6 in your text book or google the Web; if you use the Web, then you must include the link(s) you used for help you formulate your response.
Respond to item 2 by explaining what it means to overload a function, be concise and to the point
Respond to item 3 by comparing and contrasting actual and formal parameters, be concise and to the point
Respond to item 6 by explaining the difference between value and reference parameters, be concise and to the point
Explanation / Answer
1.Respond to item 2 by explaining what it means to overload a function, be concise and to the point
To overload a function means to have the same name for more than 1 functions but to have different prototypes. For example we need to find the area of shapes, here we can use overloading. For examole.
double area(int side);//Area of square
double area(int length, breadth)//Area of rectangle
double area(double radius);//Area of circle
We have overloaded 3 function each of them has the same name area() but different parameters or prototypes.
***************************************************************************************************************************
2.Respond to item 3 by comparing and contrasting actual and formal parameters, be concise and to the point
The parameters which are passed in the function call are known as actual parameters and the parameters which are received by the called function are known as formal parameters. For Eg.:
void main() {
int x=10;
int y = 20;
z = add(x,y);
}
int add(int a, int b){
return a+b;
}
In the above example, x and y are known as actual parameters and a and b are known as formal parameters.
***************************************************************************************************************************
3.Respond to item 6 by explaining the difference between value and reference parameters, be concise and to the point
The main difference between value parameters and reference parameters is that, in value paramaters only the value is passed i.e if the value is changed outside the scope, its value is not affected.
But, in reference parameters, the reference is passes i.e the address of the data is passed. So if the data is changed by reference, the data is actually affected because the actual data is passed(i.e. reference is passed) and not just the value.
For eg:
}
}
In the first case any change in a and b will be affected outside because a and b are references.
But in the second case, we have a and b as value parameters and there existence ends when the control goes out of the function.
***************************************************************************************************************************
I hope this helps you. All the best. Kindly rate the answer.
void changeby10 (int& a, int& b)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.