Thread: Pointer Problem

  1. #1
    Registered User
    Join Date
    May 2009

    Pointer Problem

    Why is there no asterisk before lowest n highest in printf of 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: ");	  
    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;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    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.

    Hope is the first step on the road to disappointment.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    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.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 12:14 PM