C++Primer-Function chapter

作者:罗志强

—————————————————————————————————————————————————————————————————————————————

本文主要讲得是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






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值