-
What type of data can the following function return:
-
Write an integer function called sum which returns the sum of two numbers.
-
What is wrong with the following use of functions:
void silly ( void )
void add_one ( int input )
{
input = input + 1 ;
}
int i = 0 ;
/* make i one bigger */
add_one ( i ) ;
Answers
-
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
-
int sum ( int a , int b)
{
return a + b ;
} -
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