Just a week into C/C++. I have a function that takes a pointer to an array as an argument. Manipulating this input array inside the function results in a change in another (globally defined) array.
I need to find and return the address of the minimum value in this (globally defined) array of floats. In C++ I can do this relatively easily with std::min_element(), since this returns an iterator. Any way to do this in C? I can write a loop to find the minimum value in an array, but not sure how to access its address? Here'e the (pseduo)code.
globalArray[100] = {0}
float *DoSomething(float *array)
{
if (conditionMet == 1)
{ Do something to array that modifies globalArray;}
float min;
min = globalArray[0];
for (int i = 0; i <100; i++)
{
if (globalArray[i] < min)
min = globalArray[i];
}
return &min;
}
return &array[minIndex];?