作者:罗志强
—————————————————————————————————————————————————————————————————————————————
本文主要讲得是C++ function chapter,本文将以英语方式进行表达
—————————————————————————————————————————————————————————————————————————————
1:Function basics:A function definition typically consists of a return type.a name .a list of zero or more parameters, the parameters a specified in a comma-separated list enclosed in parentheses. for example:
===================
int function(int val)
{
int ret = 1;
while(val>1)
ret *= val--; // ret is factorial ;
return ret; // return the result;
}
====================
2:Calling a function
A function call does two things
1):It initializes the function's parameter from the corresponding arguments.
2):It transfers control to that function,execution of the calling function is suspended and execution of the called function is begin.
3:function have to two important argument: Parameters and Arguments
Parameters relation to Arguments : Arguments are initializers for a function's parameters .The first arguments initializer the first parameters the second arguments initializes
second parameters and so on. And the type of argument must match the corresponding parameters type.
form example
===================
int main()
{
int j = factorial(15); // j equals "the value very bigger " 1307674368000
// j must int the type of argument must match the corresponding parameters type
//" argument j is int type = parameters val is int type so equal type
cout<<"15 factorial" <<j<<endl;
return 0;
}
int function(int val) // int : return type is int let's me say "Function Return type " every function must be return one type can't return
// no-return type the complier can't compliers
{
int ret = 1;
while(val>1) // loop
ret *= val--; // ret is factorial ;
return ret; // return the result;
}
====================
4:Local objects
In C++ name have scope ,and objet have lifetime
===tomorrow continua