# Passing Pointers to Functions question..

• 10-18-2008
transgalactic2
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  */ }```
• 10-18-2008
Elysia
Because when the compiler sees you call addNumbers, it must know how that function looks like, and by the time it finds the function call, it must already know the function prototype.
Since the actual function is below the code calling it, you have to make a prototype at top to help the compiler.

And just a thought, but take a stab if you're interested in the difference between int* vs int *: http://www.research.att.com/~bs/bs_faq2.html#whitespace
• 10-18-2008
transgalactic2
so each time
when i am building a function i need to write its signature bellow the #include <stdio.h>
• 10-18-2008
cyberfish
Before the first time it's called. Conventionally above the definition of main().
• 10-18-2008
Elysia
Yes, it's good practice.
And it should usually be in a header file of its own, which you include too.
• 10-18-2008
transgalactic2
when you said

"Yes, it's good practice."
you meant its a good example for examining this subject

practice by my vocabulary means experience in doing some thing

or you mean practice=definition of this function signature

??
• 10-18-2008
tabstop
Practice in the sense of, say, "sound accounting practices" or "practicing medicine". "Good practice" == "Things you better do if you don't want your boss to beat you up and put you in the dumpster".
• 10-18-2008
transgalactic2
thanks