当前位置:网站首页>Value transmission and address transmission of C language, pointer of pointer
Value transmission and address transmission of C language, pointer of pointer
2022-07-29 04:02:00 【Xiaowa 123】
When the function is called : Value and address
The secondary pointer :
int a=5;
int* p=&a;
int** p1=&p;
printf("a=%d, *p=%d, **p1=%d", a, *p, **p1); The result is 5,5,5
*p: p The value of is a The address of ,p Point to a,*p Just look at p The variable value on this address ,*p Yes. p The variable value on the stored address , Not to see p The value of this variable (p The variable value of is the address , see p The variable value of should be to see p Value , Not through *p The way ,*p Is to look at pointer variables p The value of the variable on the address pointed to !)
**p1 That is to say *(*p1),*p1 Just look at p1 The variable value on the stored address ,p1 The value of is p The address of , therefore *p1 Namely p Value , therefore **p1 Namely *p=a.
* Address = The value of the variable occupying this address ≠ The value of the address
**p1:*(*p1),p1 Put pointer variables p The address of , therefore *p1 It's a pointer variable p
* Whose address = Whose value
c The value and address of language - Baidu library c
Pass value : Do not change the value of the real parameter in the main function
Byref : Pass the address of the variable in the main function directly to other functions for use , Changed the actual value of the real parameter in the main function .
The difference is this : Passing values only works inside the function , If it's an address , After a functional process , The arguments in the main function can be actually changed .
For arrays , Because arrays usually occupy a large amount of memory , The system will not copy another piece of memory in the memory space of the function for value transfer like value transfer , Instead, send the address directly , Directly change the actual parameter value of the array .
The system is quite strict with the memory of the array .
It also involves the pointer of the pointer :

Byref : You want to actually change the value of which argument through the function , Just pass in the address of this argument .
The pointer of the pointer :
If the pointer is main An argument in the main function , And want to change the value of the pointer , What should be passed to the function parameter is main Address of argument pointer in function .
The variable of which argument you want to actually change , Just pass in the address of the argument , Byref .
malloc- The pointer of the pointer - Address transmission or value transmission : Be careful : If you want to change the value of an argument through a function call , The address passed in should be the address of the argument , Instead of copying a copy of memory in the called function , This memory will disappear with the end of the called function .
malloc The allocated memory needs to be free In order to release , Apply inside the function malloc, Even if the function ends , It will not release this memory .
边栏推荐
- Object array merges elements according to a field
- Typescript from introduction to proficiency (XXIV) using import syntax
- Microcomputer principle and interface technology
- Press the missing number of interview question 17.04 | | 260. the number that appears only once (including bit operation knowledge points)
- Basic configuration of BGP - establish peers and route announcements
- Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
- Several cases of word wrapping in div
- 从2019 年开始,你一定停止使用了这个营销策略…
- 店铺排名问题,如何解决?
- Data too long for column 'xxx' at row 1 solution
猜你喜欢
随机推荐
Const read only variable constant
当我从数据库获取到了winfrom特定的控件ID之后我需要通过这个ID找到对应的控件,并对控件的TEXT文本进行赋值这该怎么做
MySQL第四篇(完结)
华为天才少年稚晖君做了一把模块化机械键盘,引起极客圈地震,网友:这才是真正的客制化...
Shopify seller: EDM marketing should be combined with salesmartly to easily get the conversion rate
SQL语句 关于字段转换怎么写
UCOS task switching process
大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?
Batch production and upload sales NFT opensea eth polygon
Press the missing number of interview question 17.04 | | 260. the number that appears only once (including bit operation knowledge points)
Let variable declaration feature of ES6 new feature and its case
Data too long for column 'xxx' at row 1 solution
消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
Remote desktop connection error
Beijing post network research 2015 problem2
Typescript from getting started to mastering (XVI) configuration file - first knowledge of compileroptions configuration item
企业网的三层架构
Several cases of word wrapping in div
一文学透MySQL表的创建和约束
MySQL第三篇









