Thread: Passing Pointers to Functions question..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    Passing Pointers to Functions question..

    why do we write only the signature of a function addNumbers at the start of the code and later we write the whole function??

    how do we define that scanf command will be separated by spaces??



    Code:
    #include <stdio.h>
    
    int addNumbers(int *fiveNumbers);  
    
    int main() {
      int array[5];
      int i;
    
      printf("Enter 5 integers separated by spaces: ");
    
      for(i=0 ; i<5 ; i++) {
        scanf("&#37;d", &array[i]);
      }
    
      printf("\nTheir sum is: %d\n", addNumbers(array));
      return 0;
    }
    
    int addNumbers(int *fiveNumbers) {  /* define function */
      int sum = 0;
      int i;
    
      for(i=0 ; i<5 ; i++, fiveNumbers++) {
        sum+= *fiveNumbers);            /* work out the total */
      }
      return sum;                       /* return the total   */
    }
    Last edited by transgalactic2; 10-18-2008 at 02:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Structure Pointers to Functions
    By samus250 in forum C Programming
    Replies: 15
    Last Post: 03-20-2008, 03:13 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question about pointers
    By maxhavoc in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2004, 12:46 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Pointers, arrays , functions
    By sballew in forum C Programming
    Replies: 19
    Last Post: 09-16-2001, 11:12 PM