111k views
1 vote
Write a statement that declares a prototype for a function divide that takes four arguments and returns no value . The first two arguments are of type int . The last two arguments arguments are pointers to int that are set by the function to the quotient and remainder of dividing the first argument by the second argument . The function does not return a value

2 Answers

6 votes

Answer:

void divide (int x, int y, int*q, int*r);

Step-by-step explanation:

MPL

Write a statement that declares a prototype for a function divide that takes four-example-1
User Tonymarschall
by
5.1k points
1 vote

Answer:

void divide(int numerator, int denominator, int *quotient, int *remainder)

{

*quotient = (numerator / denominator);

*remainder = numerator % denominator;

}

Step-by-step explanation:

this exercise is to learn the syntax of passing by pointers. Pointer arguments are special. This is because, conventional arguments, when passed, make a copy of the argument received and manipulate that copy. Afterwards, that copy is deleted. Pointer arguments are used when the original argument, in this case the quotient and the remainder, need to be altered in the program. How it works is, when passing by pointer, the computer goes inside the memory, finds the location of the pointer, and edits it there, IT DOES NOT MAKE A COPY IN THIS CASE.

User Thennarasan
by
4.6k points