The function row_stats is supposed to update the value stored by variable max_ptr with maximum number from a given row of the array. I tried looking it up in other questions here but it didn't help. Could someone please explain me where is the mistake?
#include <stdio.h>
void row_stats(int(*ptr)[5], int width, int row_id, int* max) {
int i = 0;
int curr = ptr[row_id][0];
while (i < width) {
if (ptr[row_id][i] > curr) {
curr = ptr[row_id][i];
}
i++;
}
max = &curr;
printf("max: %d\n", *max);
}
int main() {
int a[5][5] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20},
{21, 22, 23, 24, 25}
};
int* max_ptr;
row_stats(a, 5, 3, max_ptr);
printf("after funct: %d", *max_ptr);
return 0;
}