C语言编程学习课件 (36).pdf
《C语言编程学习课件 (36).pdf》由会员分享,可在线阅读,更多相关《C语言编程学习课件 (36).pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Programming In CProgramming In C The essence of calling function A C program can be composed of a main()function and several functions,and the tasks are completed by mutual calls between functions.Parameters are the main channel for data exchange between functions.Therefore,a thorough understanding
2、of the parameters in a function and a grasp of the mechanism of parameter transfer are not only a prerequisite for the correct design and skillful application of functions,but also the key to program design and development.The essence of calling function The essence of a parameterized function call
3、is to replace the formal parameters with actual parameters.Parameters are used to pass messages between different code blocks of a program.The actual parameters used in a function call must be exactly the same as the formal parameters in order,number,and data type.Programming In CProgramming In C#in
4、clude stdio.h float f(float x,float y)float s;s=2*x*x+3*y+8;return s;void main()float a=1.2,b=3,result;result=f(a,b);printf(%6.2fn,result);(2)x=1.2 y=3 s=19.88(1)funtion be called x,y,s be created in memory Procedure of calling function formal parameter workingformal parameter working the function b
5、ody be runningthe function body be running return return s (3)result=19.88 E.g.4:solvtion of f(x,y)=2x2+3y+8 Programming In CProgramming In C 1.pass by value Value passing takes constants,variables and expressions as actual parameters and passes values to the corresponding formal parameters.The actu
6、al parameter value is copied to the formal parameter which is completely isolated from the place that the information came from.So,any change of the formal parameter is not related to the actual parameter.Therefore,value passing is one-way.Array names,function names,pointers,etc.Can also be passed a
7、s actual parameters to formal parameters,in which case addresses are passed instead of values.Address passing is two-way.result E.g.2:one-way value passing#include stdio.h main()int a=2,b=3;swap(a,b);printf(“(2):a=%d,b=%dn,a,b);(1):a=3,b=2 (2):a=2,b=3 Function parameter passing 2.pass by address voi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言编程学习课件 36 语言 编程 学习 课件 36
限制150内