C指针,&,*,指针的指针
C指针: 指向变量的地址,想象成房间号
&: 取地址符号
*:间接访问符号, 访问p所存地址的内容
#include <iostream> int main(int argc, const char * argv[]) { int m = 5; int *p = &m; std::cout << "p = " << p << std::endl; //0x7ffeefbff5bc std::cout << "*p = " << *p << std::endl; //5 return 0; }
#include <iostream> int main(int argc, const char * argv[]) { int m = 5; int *p = &m; std::cout << "p = " << p << std::endl; //0x7ffeefbff5bc std::cout << "*p = " << *p << std::endl; //5 std::cout << "&p = " << &p << std::endl;//0x7ffeefbff5a0 int **pp = &p; //& 不可以使用两次 int b = **pp; std::cout << "b = " << b << std::endl; //5 std::cout << "*pp = " << *pp << std::endl;//0x7ffeefbff58c std::cout << "pp = " << pp << std::endl;//0x7ffeefbff570 return 0; }
另外注意指针要初始化,否则成为野指针。
参考 https://www.cnblogs.com/mymindview/p/5247485.html
此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935.
我的gitHub: (学习代码都在gitHub)
https://github.com/nwgdegitHub/