当前位置:网站首页>Pointer function (basic)
Pointer function (basic)
2022-07-05 04:23:00 【Cao Lele loves learning】
Write a function of pointer type , Return a pointer , however :

This has been explained before :

therefore , When a function is called , Return value , There is no problem ; Because the address space of the return value in the function is before it is released , The value has been assigned to the function name , and The return address When , This address space has been released ( Personal understanding , Not necessarily right ).
There is no problem to return the address :
1、 Set global variables —— Don't suggest
2、 Set static variables —— As the case may be ()

Compare :
Return value :

The return address ( The return value is the function pointer ):
local variable , You cannot return the address and take another value :
To modify the storage type , Make it after the function call , Memory is not released :

attach : String concatenation —— The same data content will be passed , From an address space , Copy to another address space
The function prototype char *strcpy(char *dest, const char *src);
Function pointer exercise : imitation strcat function , Realize your own string connection

Be careful : Priority of self increasing operator > Value priority , therefore *str++ ==> *(str++)
And i++ equally , It's just a variable i, One is the pointer variable *p; In fact, they all use it first , add :
i++ First i Value , then i Value ++
*p++ First *p Value , then p The address of ++
Take it apart and write it :
*str
str++

therefore :*str1++ = *str2++; In fact, that is *(str1++) *(str2++);
It needs to be straightened out :*(str1++) *(str2++); Is not str2 Address increment ,str2 Address increment , And then take str2 Incremented value , Assign a value to str1 The position after the address is incremented . But with a++ = i++ equally
Take respective values first , To assign a value , Then increase the address :
*str1 =*str2;
str2++;
srt1++;
------------------------------------------------------------------------------------------------------------------
practice 2: Imitate string to integer function :atoi.

Write your own integer to string :inttostr

Ideas :
1、 First, use a loop to remainder the integer , And remove the lowest bit
2、 character ’0‘ And integers 0, Difference between 48, That is to say ’0‘
3、 Will screen out each one , Put it in an array ( At this time, it is the opposite , The lowest position ran to the far left )
4、 In exchange for
( because aa[i], After the conversion is complete , An artificial one ’\0‘, therefore i--, Go to the last character aa[i], Find another variable n From an array aa[0] Start swapping , And walk towards the middle .)
therefore :
The penultimate character is exchanged with the first character
The penultimate character is exchanged with the second character
........ With i--;j++; if i=j, Then the data is an odd number ; if i<j, Then the data is an even number
If it's an odd number ,i=j When , Don't move the middle character ; Even number of hours , When i<j When , The two data in the middle have been exchanged .
There's another problem : In the above code , Function defines a static array , The size is fixed ; that , If the parameter passes an array in , Is it better ?

边栏推荐
- How to get the first few pieces of data of each group gracefully
- Burpsuite grabs app packets
- Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
- Un réveil de l'application B devrait être rapide
- 长度为n的入栈顺序的可能出栈顺序
- [thingsboard] how to replace the homepage logo
- How to carry out "small step reconstruction"?
- Ctfshow 2022 Spring Festival welcome (detailed commentary)
- Interview related high-frequency algorithm test site 3
- MacBook安装postgreSQL+postgis
猜你喜欢

假设检验——《概率论与数理统计》第八章学习笔记

陇原战“疫“2021网络安全大赛 Web EasyJaba

What is the reason why the webrtc protocol video cannot be played on the easycvr platform?

Threejs realizes sky box, panoramic scene, ground grass

Serpentine matrix

Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...

【虚幻引擎UE】运行和启动的区别,常见问题分析

MacBook安装postgreSQL+postgis

Rust blockchain development - signature encryption and private key public key

User behavior collection platform
随机推荐
Network layer - forwarding (IP, ARP, DCHP, ICMP, network layer addressing, network address translation)
How to realize real-time audio and video chat function
Power management bus (pmbus)
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
直播预告 | 容器服务 ACK 弹性预测最佳实践
Ffmepg usage guide
Fuel consumption calculator
Realize the attention function of the article in the applet
【FineBI】使用FineBI制作自定义地图过程
如何实现实时音视频聊天功能
level17
Sequence diagram of single sign on Certification Center
技术教程:如何利用EasyDSS将直播流推到七牛云?
Threejs factory model 3DMAX model obj+mtl format, source file download
Function (error prone)
Burpsuite grabs app packets
Threejs Internet of things, 3D visualization of farms (I)
Longyuan war "epidemic" 2021 network security competition web easyjaba
Sword finger offer 04 Search in two-dimensional array
函数(基本:参数,返回值)