当前位置:网站首页>Pointer learning diary (I)
Pointer learning diary (I)
2022-07-24 05:14:00 【Rain and cold at night in Xiaoxiang】
#include
#include
using namespace std;
int main()
{
char* p;
char ch = ‘a’;
p = &ch;
cout << *p << endl;
return 0;
}
You can put char* As a new definition , The value of the variable under this definition is char The address of the type value .
* Operators are indirect access operators , It works with pointers , Used to access the value pointed to by the pointer .
In defining char* p The time should be char* And int,long,char,string The same variable definer .
Defining variables p Is a pointer variable ! Pointer variables store addresses .* Is the value of the address stored by the access pointer variable
A few pointers that are easy to get wrong
*cp+1:* Priority is higher than +, So let's take it first cp A copy of the value pointed to , Add the copy value 1
++cp And cp++; These two are completely different ,++cp Is the addition of variables cp Value ( Variable cp The value of is the address , Then add 1 after , Namely cp The result of the next bit storage space expression of this address is cp I added , And the return value is cp Increased value )
and cp++ Return first cp A copy of the value is increased cp Value . Is to return first cp Original value , let cp+1;
for example : hypothesis cp The value of is x25( There is no doubt that it can not ! Just make an assumption , Storage space takes up one ).
that cp++ The return is x25,++cp The return is x26;! But pay attention to , The two methods ,cp The end result is x26, It's just that the return value is different .Here we go !*++cp And ++*cp The difference between :
*++cp, Indirect access operators ( That is, the asterisk ) Copy of the pointer acting on the increment
*cp++, suffix ++ The operator takes precedence over the indirect access operator , But the value returned by this expression is cp Original value , It seems that the indirect access operation is performed first , Actually, it involves 3 A step :++ Operators produce cp A copy of ; then ++ The operator adds cp Value ; Last , stay cp Perform indirect access operations on the replica .++cp: I want to code this explanation
#include
#include
using namespace std;
int main()
{
char p;
char* k;
char ch = ‘a’;
p = &ch;
k = p;
*p = ‘b’;
cout << ++*p <<” “;
cout << *k << endl;
return 0;
}
The final result is c c, That is to say, first visit indirectly p operation , Will be p The value of the pointed position increases 1, At this time !ch The value of has really changed
边栏推荐
- Jetson device failed to download repository information use tips to record
- Kingbase V8R6集群安装部署案例---脚本在线一键扩容
- finally和return的执行顺序
- [database connection] - excerpt from training
- Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life
- 2. Input a circle radius r, when r > = 0, calculate and output the area and perimeter of the circle, otherwise, output the prompt information.
- 排序——QuickSort
- All sections need to be able to have a problem system port, the first subscript. Many machines become
- Crazy God redis notes 09
- Using a* heuristic search to solve maze routing problem
猜你喜欢

酒店IPTV数字电视系统解决方案
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

排序——QuickSort

This article takes you to understand C string functions and memory functions in simple terms

Scikit learn -- steps of machine learning application development

利用a*启发式搜索解决迷宫寻路问题

On the dilemma faced by non transferable reputation points NFT SBTS

Image painting for irregular holes using partial revolutions paper notes

The second chapter is encog's data acquisition

Want to know how a C program is compiled—— Show you the compilation of the program
随机推荐
Accuracy of% connections. Now it is planned to meet the demand. The number of enterprises is enough
XML schema
Some thoughts about blogger coach soserious
un7.23:如何在linix上安装MySQL?
GOM engine starts M2 prompt: [x-fkgom] has been loaded successfully. What should I do if it gets stuck?
[database connection] - excerpt from training
NLP learning roadmap (mind map) is very comprehensive and clear!
The network NN can calculate the NTCP provided by the host system
frp内网穿透服务使用
Learning pyramid context encoder network for high quality image painting paper notes
Un7.23: how to install MySQL on linix?
Foreign key operation of MySQL_ Cascade operation
几种常见的排序
Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life
Hcip-- review the homework for the next day
Do you want to have a robot that can make cartoon avatars in three steps?
Chapter 9 using image data
Drools 开发决策表
Icml2022 | rock: causal reasoning principle on common sense causality
Kingbase V8R6集群安装部署案例---脚本在线一键缩容