当前位置:网站首页>Explain in detail the differences between real participation formal parameters in C language
Explain in detail the differences between real participation formal parameters in C language
2022-06-11 13:05:00 【Please trust me】
List of articles
Basic concepts
It is no wonder that we have seen so many concepts about shape participation arguments , Here we will deepen our impression or understanding . Actual parameters : The so-called argument is the variable parameter of the space actually opened up in memory . Shape parameter : It refers to the parameters of the function , It is called formal parameter , The reason is that only when the function is called will the variable be given a value in Stack Open up space in , And will The argument is copied to the formal parameter
Case study 1
Here I'll just go up the pointer , We understand the pointer , Everything and understand , Please look at the following code
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void func(char * buffer){
printf("%x\n",buffer);
if(buffer){
free(buffer);
buffer=NULL;
}
return ;
}
int main(){
char *buf=NULL;
printf("%x\n",buf);
buf =(char *)malloc(100);
if(buf==NULL){
printf("test_1\n");
}
func(buf);
if(buf==NULL){
printf("test_2");
}else{
printf("test_3");
}
return 0;
}
What is the print result of the final program ?
Case study 2
Please look at the following code
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void swap(int * a,int *b)
{
int *temp;
temp = a;
a=b;
b=temp;
printf("%d %d\n",*a,*b);
return ;
}
int main(){
int a=6;
int b=10;
int *p,*q;
p=&a;
q=&b;
swap(p,q);
printf("%d %d\n",*p,*q);
return 0;
}
What is the output of this code ?
answer
Case study 1:
answer :test_3
The analysis is as follows :
We applied for results on the heap 100 Bytes of space ,malloc Function will return the address on the heap address of the successful application , So I can't print test_1 Of , Then we call the function func, Go to Release parameter buffer, This space on the heap must have been released . And buffer It's empty , But it's none of our business buf What does it matter , therefore buf Not for NULL, The answer is test_3
Case study 2
answer :10 66 10 The principle is the same as the case 1, Grasp the relationship between actual parameters and formal parameters, and grasp the content copy OK

边栏推荐
- Dbutil auxiliary class, manual commit transaction, metadata
- 综合场馆的优势有哪些?
- Audio adaptation of openharmony Standard System Porting
- live share使用体验
- Go语言学习之WaitGroup用法详解
- What scenarios can the member management system of the multi guest swimming pool achieve?
- 【backtrader源码解析46】cerebro.py代码注释(枯燥,backtrader核心代码之一,推荐阅读,注释仅供参考)
- 4. Locksupport and thread interruption
- Log management system, summary in multiple ways
- How can mechanical equipment manufacturing enterprises manage outsourcing with the help of ERP system?
猜你喜欢

Luo Jing: connection Efficiency Optimization Practice

@Controller和RequestMapping如何解析的

Adobe Premiere基础-批量素材导入序列-变速和倒放(回忆)-连续动作镜头切换-字幕要求(十三)

Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement

What are the ways for badminton halls to generate income

详解C语言实参与形参的区别

【bug解决】表单分页,显示总数据res.data.total

关于分布式锁的续命问题——基于Redis实现的分布式锁
![[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]](/img/1a/7b80f3d81c1f4773194cffa77fdfae.png)
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]

In the list of 618 projector hedging brands in 2022, dangbei projection ranked top 1 in the hedging rate of idle fish
随机推荐
【问题总结】$t
@Controller和RequestMapping如何解析的
场馆坪效这么低?关键在这两方面
#61. Two point answer
模态框关闭后清空模态框里选择的数据
历史上的今天:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生...
Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement
[untitled]
【bug解决】上传图片后,取消这次上传 再次执行上传,上次的图片还存在
从QUIC到TCP
PADS使用之繪制原理圖
kubernetes 二进制安装(v1.20.16)(五)验证 master 部署
常用字体介绍
Which brand of bone conduction Bluetooth headset is good? Five most popular bone conduction Bluetooth headsets
What are the advantages of comprehensive venues?
微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
jdbctemplate数据后台管理,不知道为什么添加用户的时候显示roleId为空
逆向学习入门-优秀的汇编调试工具OllyDbg
The Tree (AVL, 2-3-, 红黑,Huffman)
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]