last modified 5/19/03

Functions

Here is the basic structure of a function:

return_type function_name (arg_type arg_name, arg_type arg_name, etc...) {

< statements >

return value;

}

 

 


Questions from Students

  1. is it true that you cannot modify the argument of a function? I think that the king books says if you modify and return the variable, it would be the same as the original one. but I tried the following code which does modify its argument, and it works! I am confused.
    int leadingDigit (int n) {
       while(n>=10)
         n/=10;
       return n;
    }
    

     

main page