function implementation and prototypes?

We have a test on tuesday, and I was hoping to get some step by step help on implementing functions and identifying their prototypes. I went to the tutorial, but still don't fully understand. Can someone please direct me somewhere with examples on how to implement a function and display it's prototype?
A functions prototype is its name, what kind of object it returns, and what kind of object(s) it accepts.

The format is as follows:

typeOfObjectReturned nameOfFunction(firstKindOfObjectIn name1, SecondKindOfObjectIn name 2, ...)

Here's an example.

int main(void);

This is the prototype for a function called main that returns an int and accepts no input arguments.

Here's another one:

passenger eatSomeChips (int beans, catArray hopelessness);

This is the prototype for a function called eatSomeChips that returns a passenger object and accept two input arguments; an int called beans and a catArray called hopelessness.


To implement the function, take the prototype and add the actual code that makes it do whatever it does.

1
2
3
4
5
passenger eatSomeChips (int beans, catArray hopelessness)
{
  // Lots of code in here
  //   return a passenger object.
}
Last edited on
Also, function prototypes do not have to have names given for their parameters, so keep that in mind as it may be part of your test.
Thank you! I'll practice. will return with examples I have completed.
you almost never actually need function prototypes. all they let you do is call a function that you havent defined yet. you can just define all of your functions at the top of your program and often this can be simpler and easier :)
You'll need them if you're using library functions.
i quote myself: you ALMOST NEVER

perhaps this is still a bit of an exageration though :o
Topic archived. No new replies allowed.