Is using multiple function parameters for the purpose of returning multiple values in C bad practice?

Qwertie

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?

paulsm4

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.

edited at
0

Comments

0 comments
Login to comment

Related

Returning multiple values from a function in C

Returning multiple values from a C++ function

Python mock values using side_effect but for a function which is returning multiple parameters

Best practice for a Java method returning multiple values?

Best practice for returning multiple values in Java?

Function returning unwanted multiple values

Returning multiple values from function

COUNT(*) function is returning multiple values

Returning multiple values from a function in variables using bash script

Returning multiple values using multiple matching criteria

Efficiently returning multiple values in C

returning multiple values from recursive function c++

c function and multiple value returning

C++ function providing multiple values: reference parameters, or tuple?

Using a function with multiple parameters with `map`

Issue returning multiple values with a tuple for a function

Returning multiple values from PL/SQL function

Python Returning multiple values into another function

Returning multiple parameters

Using while on a method returning multiple values

Updating and returning multiple values using the state monad

Error when returning multiple values to threads in C

C++ Returning Multiple Values with a Struct

How to pass multiple list values as function parameters?

Returning multiple values: Return array vs change referenced parameters

Returning the value of a function with multiple input parameters to use in another function with multiple parameters inside the same Class?

returning multiple arrays from a function in c++

Returning multiple values in UDF

returning multiple values in Java