Works for me
Code:
#include <stdio.h>
#include <string.h>
int maxarray(int s, int d[])
{
int lo = 0;
int i = 0;
for (; i < s; i++) {
if (d[i] > d[lo]) {
lo = i;
}
}
return (d[lo]);
}
int maxptr(int s, int *d)
{
int lo = 0;
int i = 0;
for (; i < s; i++) {
if (*(d + i) > *(d + lo)) {
lo = i;
}
}
return (*(d + lo));
}
int main()
{
int test[] = { 1, 45, 23, 244, 11, 34, 2 };
printf("%d\n", maxarray(7, test));
printf("%d\n", maxptr(7, test));
return 0;
}
$ gcc -W -Wall -ansi -pedantic foo.c
$ ./a.exe
244
244
> The forumula to convert array[i] is (address of array's first element + (the index * size of one element)).
Except C already takes this into account based on the type of the pointer.
arr[ i ] is just *( arr + i )