Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C++ defines a pointer to a variable, outputs the value of the pointer and the address of the variable, and modifies the value of the variable through the pointer.
C++ defines a pointer to a variable, outputs the value of the pointer and the address of the variable, and modifies the value of the variable through the pointer.
int I = 10; //Define an integer variable with an I value of 10.

Int * p = & //Define an integer pointer variable p, pointing to the variable I, and note that only those of the same type can point to it.

Cout < < * p < < endl//outputs the value of the variable I pointed to by P, plus * indicates that the output is the value of the variable pointed to by the pointer.

Cout & lt& ltp<& ltendl// Output p points to the address of the variable I, and the value of p itself is not indicated by *.

* p = 20// Because the * indicates that p points to the value of the variable, the data of the variable I can be modified in this way.

//At this time, change the value of I to 20 through the pointer p..