141k views
0 votes
doubleIt is a function that takes one argument and returns no value . The argument is a pointer to int . The function doubles the value that the argument points to and stores it back.savings is an int variable that has been declared and initialized .Write a statement that doubles the value stored in savings by invoking the function doubleIt . For example, if the value in savings was 7 before your statement , after your statement its value would be 14.

2 Answers

2 votes

Answer:

void doubleIt (int * x)

{*

x =*x * 2;

}

Step-by-step explanation:

MPL Answer

User Kamath
by
5.0k points
4 votes

Answer:

void doublelt(int *number)

{

*number=*number*2;

}

Step-by-step explanation:

This exercise is for you to learn and understand the PASS BY POINTER syntax. The importance of this is that if you didnt use a pointer you would have to RETURN an int from the function. in that case the code would be:

int doublelt(int number)

{

number=number*2;

return number;

}

Passing by pointer manipulates the value by going inside the memory and where it resides. Without the pointer, the function would create COPIES of the argument you pass and delete them once the function ends. And you would have to use the RETURNED value only.

User Clocker
by
5.1k points