In this recipe, all the elements of the array will be scanned using pointers.
Finding the largest value in an array using pointers
How to do it…
- Define a macro by the name max with a size of 100 as follows:
#define max 100
- Define a p integer array of a max size, as demonstrated in the following code:
int p[max]
- Specify the number of elements in the array as follows:
printf("How many elements are there? ");
scanf("%d", &n);
- Enter the elements for the array as follows:
for(i=0;i<n;i++)
scanf("%d",&p[i]);
- Define two mx and ptr pointers to point at the first element of the array as follows:
mx=p;
ptr=p;
- The mx...