1) why do local variables lose their values between calls to a function in which
ID: 3552982 • Letter: 1
Question
1) why do local variables lose their values between calls to a function in which they are defined?
6) How would multiple values be returned from a function?
correct the following and leave comments for the errors
2) // displays the function parameter
void display( double a )
{
float a; //
cout << a << endl;
}
3) // returns the product of the parameters
void product( int a, b, c )
{
int result;
cout << "Enter 3 integers: ";
cin >> a, b, c;
result = a * b * c;
return result;
}
Find the errors
58)
void area( int length = 30, int width)
{
return length* width;
}
60) (overloaded function)
int getValue()
{
int inputValue;
cout <<
Explanation / Answer
Dear,
1) Local variables by definition are those which are limited to particular block or function. for ex: let us assume a varible temp in function.
int swap( int a , int b)
{
int temp;
temp = a;
a= b;
b= temp;
}
2) Multiple values can be returned from function using call by reference. Here parameters are passed by reference.
2)
// displays the function parameter
void display( double a )
{
float a; //Re declaration
cout << a << endl;
}
3)
// returns the product of the parameters
void product( int a, b, c )//parameter declaration wrong
{
int result;
cout << "Enter 3 integers: ";
cin >> a, b, c;
result = a * b * c;
return result;
}
58)
//return type must be int
void area( int length = 30, int width)
{
return length* width;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.