How to define and use pointers in C++
This article mainly explains "how to define and use pointers in C++". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to define and use pointers in C++".
1 the basic concept of pointer
Function: memory can be accessed indirectly through pointers.
Memory numbers are recorded from 0 and are usually represented by hexadecimal numbers. You can use pointer variables to save addresses.
2 definition and use of pointer variables
Pointer variable definition syntax:
Data type * variable name; & you can take the address; * you can take the value stored by the address
Example:
# includeusing namespace std;int main () {int a = 10; / / 1. Syntax for pointer definition: data type * pointer variable name; int* p; / / int* defines a pointer variable p = & a; cout pointing to an integer type