当前位置:网站首页>Some summary about function
Some summary about function
2022-07-25 22:11:00 【Xiaotang blog】
One : Function call procedure
1. Memory space : Defining formal parameters in a function , When there is no function call , They do not occupy memory storage units , When a function call occurs , function max When the formal parameter of is zero, the memory unit is allocated .
2. The transmission of value : Pass the value corresponding to the argument to the formal parameter , Parameter values for 2, hold 2 Pass to the corresponding formal parameter , Then the formal parameter gets the formal parameter x Get the value 2, Formal parameters get values 3.
3. Worth returning : adopt return Statement to bring the value of the function back to the main function , In the following code , The specified return value is z, This is the of the function max Value ( Also called return value ). perform return Statement brings the return value of this function back to the calling function main, It should be noted that the type of the return value is the same as the function type . Such as max Function is int type , A variable that returns a value z, It's also int type , Two to the same .
#include <stdi#include <stdio.h>
int getMaxFromData(int x,int y){
int sum;
if(x>y)
{
z=x;
}else
{
z=y;
}
return z;
}
int main()
{
int data1;
int data2;
int bigOne;
printf(" Please enter two numbers :\n");
scanf("%d%d%d",&data1,&data2);
bigOne=getMaxFromData(data1,data2);
printf(" The two numbers you enter are :%d,%d\n",data1,data2);
printf(" The largest of these two numbers is %d, The smallest is %d\n",bigOne);
printf("\t Program end !");
return 0;
}
4. Memory free : At the end of the call , The parameter unit is released . Be careful *** The argument unit retains and maintains its original value , There is no change , If when executing a called function , The value of formal parameter changes , Does not change the value of the argument of the calling function . such as : If it's executing max In the process of function ,x and y The value of a 10 and 15, but a and b Still 2 and 3; This is because the real participation parameter is two different storage units .
#include <stdio.h>
int test(int x)
{
printf("test Function x The memory storage address is :%p, Values are :%d\t",&x,x);
int y;
return y;
}
int main()
{
int x;
int y;
printf(" Please enter a number :\n");
scanf("%d",&x);
printf("main Function x The memory storage address is :%p, Values are :%d\n",&x,x);
y=test(x);
return 0;
}
Two : Condition of function call
1. Function has been defined
2. Call library function : If you use library functions , It should be used at the beginning of this document #include The instruction includes the information needed to call the relevant library functions in this document , Columns such as , Instructions that have been used in previous chapters
#include <stdio.h>
among “stdio.h” It's a header file . stay stdio.h The file contains the declaration of input and output library functions . If not “stdio.h” Information in the file , You cannot use functions in the input / output library , Also use the functions in the math library , Should use the :
#include <math.h>
h Is the suffix used in the header file , Indicates that it is a header file ,(header fire)
边栏推荐
- 关于接口测试你想知道的都在这儿了
- Redis foundation 2 (notes)
- C语言:随机生成数+冒泡排序
- dovecot 设置邮箱quota
- [assembly language 01] basic knowledge
- Redis master-slave architecture lock failure problem (master-slave)
- 微信发卡小程序源码-自动发卡小程序源码-带流量主功能
- All you want to know about interface testing is here
- ansible+Crontab批部署巡检
- Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function
猜你喜欢

The second short contact of gamecloud 1608

Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function

五种分配方式是否会产生内部碎片、外部碎片

Sofa weekly | open source person - Niu Xuewei, QA this week, contributor this week

『SignalR』.NET使用 SignalR 进行实时通信初体验

Children's programming electronic society graphical programming level examination scratch level 1 real problem analysis (judgment question) June 2022

【汇编语言01】基础知识
![[hand tear STL] BitSet (bitmap), bloom filter](/img/bc/a6e3c2ccce478460a2742852eee9cf.png)
[hand tear STL] BitSet (bitmap), bloom filter

6-18 vulnerability exploitation - backdoor connection

TS:typora代码片段缩进显示异常(已解决)-2022.7.24
随机推荐
Animation curves are used every day. Can you make one by yourself? After reading this article, you will!
Golang: MVC models
C语言左值和右值说明[通俗易懂]
vim用法记录
How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
8000 word super detailed custom structure type
Redis基础2(笔记)
YUV420 YUV420sp 图像格式「建议收藏」
Redis为何选择单线程?
JSP初识
El expression improves JSP
c sqlite ... ...
Solutions to the failure of win key in ikbc keyboard
[fan Tan] in detail: lower control, upward management, upward drawing cake.
Redis内存淘汰机制?
五种分配方式是否会产生内部碎片、外部碎片
Why is the integer type 128 to byte -128
Special class design
核电站在席卷欧洲的热浪中努力保持安全工作