-
Pointer Problem
Why is there no asterisk before lowest n highest in printf of main?
Code:
main()
{
...
printf("The average monthly rainfall in Melbourne is %.2fmm,\n" , total / 12);
printf("The lowest rainfall of %.2fmm falls in %s,\n" , rainfall[lowest] , month[lowest]);
printf("The highest rainfall of %.2fmm falls in %s,\n" , rainfall[highest] , month[highest]);
printf("Press [Enter] to exit: ");
getchar();
return 0;
}
double rainStats(double rainfall[] , int * lowest , int * highest)
{
int i;
* lowest = 0;
* highest = 0;
double total = rainfall[0];
for (i = 0 ; i < MONTHS ; i++)
{
total += rainfall[i];
if(rainfall[i] < rainfall[* lowest])
* lowest = i;
if(rainfall[i] > rainfall[* highest])
* highest = i;
}
}
-
I assume it's because they're local to main. You didn't actually include them, so all we can do is play mind reader.
Quzah.
-
They're specifically declared as pointers in rainStats, which is because they're basically both out parameters. Any resemblence to the names of variables declared in main is purely coincidental.
Some would declare 'lowest' and 'highest' within the rainStats function as 'pLowest' and 'pHighest' instead, which emphasizes the fact that they are different variables, and are in fact pointers.