Example Analysis of C++ pointer
Editor to share with you an example analysis of C++ pointers, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!
Interview questions (pay attention to details)
Int main () {char* c [] = {"ENTER", "NEW", "POINT", "FIRST"}; char**cp [] = {% s\ n ", cpp [- 1] + 1); char***cpp = cp;printf ("% s\ n ", * * + + cpp); printf ("% s\ n ", *-- + + cpp+3); printf ("% s\ n ", * cpp [- 2] + 3); printf ("% s\ n ", cpp [- 1] [- 1] + 1); return 0;}
Do you get confused when you look at it? it doesn't matter. Let's draw a picture and talk about it.
Does this seem much more obvious, but it still needs careful analysis to make sure it is foolproof.
Print for the first time
Do + + p first and then dereference twice. As you can see in the picture below, we print POINT
Second printing
Start with + + CPP and then dereference-- change Clear1 to C, then dereference again, and finally + 3.
The printed result here is ER.
The third print
Let's start with the operation of CPP [- 2], which is equivalent to * (CPP-2), but also note that the value of our CPP has not changed here.
Here the direction of our (CPP-2) is represented by a black line, then dereferenced again, and finally + 3, which points to the ST in the figure.
So we print ST here.
The fourth print
CPP [- 1] is * (CPP-1) the CPP [- 1] [- 1] here is equivalent to * (* (CPP-1)-1) and finally + 1 points to EW.
Finally, we run the program to see the results.
The above is all the contents of this article "sample Analysis of C++ pointers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!