Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The C++ class pointer of C language is not well understood. Are there some easy-to-understand examples to explain the pointer ~!
The C++ class pointer of C language is not well understood. Are there some easy-to-understand examples to explain the pointer ~!
A variable corresponds to a unit in memory (we call it an object).

An object consists of an address (the location of the object in memory), a type (the data type that can be stored) and a value.

An object with a name is called a variable, and we can refer to an object directly with the variable name. Of course, you can also refer to an object by its address, but how do we know its address?

The address "points" to a storage unit, which we call a pointer figuratively. A variable with an address (pointer) is called a pointer variable (commonly called a pointer). Therefore, we can refer to an object with a pointer instead of a variable name.

Such as int my _ int = 0;; We define a variable named my_int, which corresponds to a memory object of the int class and has a value of 0. We can use My_int to directly reference this object and get its value. You can also define a pointer int * point = & My_int(int* means a pointer to int. My_int means the address of my_int), so we get a pointer to my_int object. We can refer to my_int object through this pointer: for example, if (my _ int = = * point) cout.

The above is the concept and basic usage of pointer. As you learn more, you will know the function of the pointer, so I won't say it again, lest you be confused.