How to master the pointer basis of C++
This article introduces you how to master C++ pointer basis, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
C++ pointers are just like other variables, except that general variables contain actual real data, while the pointer is an indicator. These are some basic problems of C++ pointers. It is also a very important concept in C++ pointers.
It tells the program in which area of memory the data can be found. This is a very important concept, there are many programs and algorithms are designed around pointers, such as linked lists. How do you define a pointer? Just like you define another variable, except that you precede the pointer name with an asterisk.
Let's look at an example: the following program defines two pointers, both of which point to integer data. Have you noticed the "p" prefix in front of the two variable names? This is a habit that programmers usually use when defining the C++ pointer base to improve the readability of the poop, indicating that it is a pointer. Now let's initialize these two pointers:
# include void main () {/ / declare variables: int nNumber; int * pPointer; / / now assign them values: nNumber = 15; pPointer = & nNumber; / / print out the value of the variable nNumber: cout