Personally I find the random function very helpful when working with integer arrays and trying to understand them. I second Click_here's answer and recommendation. Have a look at this code, play around with the SIZE and RAND symbolic constants and see what it outputs.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 25
#define RAND 251
int find_largest(int*, int);
int main(void){
srand(time(NULL));
int storage[SIZE];
int i;
int j;
printf("The contents of the array: ");
for(i=0;i<SIZE; i++){
j =(rand() % RAND );
storage[i] = j;
printf("%2.2d...\n", *(storage + i) );
}
printf("\nFinally the largest int is %2.2d...\n", find_largest(storage, SIZE) );
return 0;
}
int find_largest(int* the_array, int elements){
int cur;
int largest;
largest = the_array[0];
printf("Initially the largest is %2.2d..\n", largest);
for(cur = 1; cur < elements; cur++){
if(the_array[cur] > largest){
largest = the_array[cur];
printf("The largest is now %2.2d...\n", largest);
}
}
return largest;
}