1. What type of data can the following function return:

  2. void silly ( void )

  3. Write an integer function called sum which returns the sum of two numbers.

  4. What is wrong with the following use of functions:

void add_one ( int input )
{
input = input + 1 ;
}

int i = 0 ;

/* make i one bigger */
add_one ( i ) ;













Answers
  1. This is a trick question, a void function is not able to return any value at all. The compiler will stop anyone trying to do x = silly() because it knows that silly doesn't do anything

  2. int sum ( int a , int b)
    {
    return a + b ;
    }

  3. The problem is you can only send parameters into functions. Changing the value of a parameter will not change the variable passed as a parameter