I'm learning C and I just had the exercise to write a function that checks for the lower one of two floating-points. So I thought, I either could use pointer and also return the pointer of the lower value - otherwise, I simply could use the values and return the lower value.
double* pointer_min_value(double* first, double* second){
return *first > *second ? second : first;
}
double calc_min_value(double first, double second){
return first > second ? second : first;
}
int main() {
printf("Enter two numbers to define the minimum!\n");
double first, second;
scanf("%lf%lf", &first, &second);
printf("The lower value is %lf", *pointer_min_value(&first, &second));
printf("The lower value is %lf", calc_min_value(first, second));
return 0;
}
they both work, but what would make more sense? should I use pointer only if I want to change the value (I mean, I should not change any of the parameters in a "get me the lowest number"-funtion), or would it be better in any other view (resources, performance,...).
static
modifier, thus with optimization, I suspect the assembler would probably be the same. \$\endgroup\$