In the code below, I'm trying to implement a function that finds the maximun and minimun of a given array. But I was trying to use a different approach. I was trying to change the memory adress of the pointers for the maximum and minimum.
Why this is not working? Should I use pointers to pointers for solving this problem?
#include <stdio.h>
#define M 5
void maxMin(int *v, int N, int *max, int *min){
int i;
printf("%d\n",*v);
printf("%d\n",*max);
for(i = 0; i < M; i++){
if(*max < *(v+i)){
max = (v+i);
}
if(*min > *(v+i)){
min = (v+i);
}
}
}
int main(){
int v[M] = {1, 3, 5, 7, 8}, *max=v, *min=v;
maxMin(v, M, max, min);
printf("MAX %d\n", *max);
printf("MIN %d\n", *min);
return 0;
}