当前位置:网站首页>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 ?

边栏推荐
- Components in protective circuit
- 【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
- 【虚幻引擎UE】实现背景模糊下近景旋转操作物体的方法及踩坑记录
- Network layer - forwarding (IP, ARP, DCHP, ICMP, network layer addressing, network address translation)
- 根据入栈顺序判断出栈顺序是否合理
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- 直播預告 | 容器服務 ACK 彈性預測最佳實踐
- 【虚幻引擎UE】实现测绘三脚架展开动画制作
- Mxnet imports various libcudarts * so、 libcuda*. So not found
- Ctfshow 2022 Spring Festival welcome (detailed commentary)
猜你喜欢

Uni app change the default component style
![[phantom engine UE] realize the animation production of mapping tripod deployment](/img/89/351641c3da7e2acdbf389bc298b75e.png)
[phantom engine UE] realize the animation production of mapping tripod deployment

About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture

Rome链分析
![[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)](/img/eb/a93630aff7545c6c3b71dcc9f5aa61.png)
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)

Use threejs to create geometry and add materials, lights, shadows, animations, and axes

File upload bypass summary (upload labs 21 customs clearance tutorial attached)

解密函数计算异步任务能力之「任务的状态及生命周期管理」

The development of mobile IM based on TCP still needs to keep the heartbeat alive

Threejs Internet of things, 3D visualization of farms (I)
随机推荐
Rome chain analysis
All in one 1413: determine base
Open graph protocol
MacBook installation postgresql+postgis
Is "golden nine and silver ten" the best time to find a job? Not necessarily
Longyuan war "epidemic" 2021 network security competition web easyjaba
Laravel8 export excel file
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
MySQL: view with subquery in the from clause limit
Function (error prone)
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
A应用唤醒B应该快速方法
行为感知系统
NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
CSDN正文自动生成目录
Un réveil de l'application B devrait être rapide
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
【科普】热设计基础知识:5G光器件之散热分析
Threejs realizes sky box, panoramic scene, ground grass