[cs13001] Questions regarding L07

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Sep 18 21:22:20 EDT 2012


> 
> First, it asks "What is the type of arguments and the type of return value and why are they important? ". What does that mean? 
> 
> Return Value is the value computed by the function. But what exactly
> are the type of arguments?  Is this it? Arguments: An expression, thus
> can be just a simple constant or variable?
> 
> Is that the type of arguments? Because I can't find anything else
> that explains argument in L07 at all?

Each function accepts the arguments of a specific type and returns a
value of a specific type. For example, sqrt() accepts the argument of
type double and returns the value of type double. This means that the
expression that is inside the parentheses will be converted to type
double and the return value - the value that substitutes the function
invocation will also be double.

For example, when the following code is executed:

       int a;
       double b = 2.5;
       int c = 4;       
       a = b + sqrt(c+5);

The integer expression c+5 will be converted to double and its value
will be 9.0 When the sqrt executes, its return value is 3.0 of type
double. The expression of the right-hand-side of the assignment
operator will have the value of 5.5 of type double. However, since
the variable on the left-hand-side of the assignment is of type int,
the expression will be converted to type int as well, the fractional 
part of the value will be dropped. Variable "a" will be assigned 5.

Thanks,
-- 
Mikhail


More information about the cs13001 mailing list