More on Functions

Published on: Tue Mar 09 2010

A function definition consists of a header and body. Header specifies return type, name and arguments list.
return_type name(int j, int i) { Body; return return_type; }
You can declare local variables inside a function. If you do not want to return a value, return type is void. There are 4 types of functions:
  1. No Input, No return value – skipline();
  2. No Input, Returns a value – srand();
  3. Input, No return value – rand();
  4. Input, Return value – sqrt();
void skipline() { Body; }
You can scanf strings
scanf(“%s”, nameArray);
Notice, the name of my array does not need to have &nameArray. That is because the name of an array without an index is actually its address. When writing functions, for every argument you must declare the type ie: RIGHT
myFunction(int I, int J) {}
myFunction(int I,J) {}
These argument declarations are called formal parameters. They reserve space in the memory.