1. The following function uses reference variables as parameters. Rewrite the fu
ID: 3547281 • Letter: 1
Question
1.
The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.
int dosomething(int &x, int &y)
{
int temp =x;
x = y * 10;
y = temp * 10;
return x + y;
}
2.
Write a function that accepts an int array and the array and the arrays size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The function should return a pointer to the new array.
Explanation / Answer
1.int doSomething(int &x, int &y)
{
int temp =x;
x = y *10;
y = temp * 10;
return x + y;
}
now my code is:
int doSomething(int *x, int *y)
{
int temp=*x;
*x= *y * 10;
*y = temp * 10;
return x+y;
}
int main()
{
int y,z;
cout << "Please enter a number" << endl;
cin >> y;
cout << "Please enter another number" << endl;
cin >> z;
doSomething(&y, &z);
system("Pause");
return 0;
}
2.#include <cstdlib>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.