If I have a function which calculates the minimum and maximum of an array would it be bad practice to include minimum and maximum in the function parameters so I can edit them while the function runs.
So I would have void minmax(array, int min, int max)
the min and max variables would be sent in as null and get changed when the function runs. Would this be ok or should I be using malloc to get an array and return the pointer instead?
Q: If I have a function which calculates the minimum and maximum of an array would it be bad practice to include minimum and maximum in the function paramiters
A: No, not at all. That's a perfectly reasonable thing to do.
Q: "So I would have void minmax(array, int min, int max)
..."
A: Uh, no. That would NOT pass "min" and "max" back to the caller. Instead, you need something like:
void minman(int * array, int * min, int * max);
'
For example:
int myarray[] = {1, 2, 3};
int min, max;
minman(myarray, &min, &max);
...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments