c++ 指针的理解
现在在自学C++,对指针有个简单的理解,如有不对的地方请朋友们指出:
#include <iostream>
int foobar(int *p) {
*p = 1024;
return *p;
}
int main() {
int i = int(1);
int *p = &i;
std::cout << "指针的值为: *p = " << *p << std::endl;
std::cout << "指针的内存地址为: &p ,这个是指针p的内存地址, **p 就指向*p这个地址。 = " << (long)&p << std::endl;
std::cout << "指针的内存地址为: p,这个是int i 的内存地址 = " << (long)p << std::endl;
int ival = foobar(p);
std::cout << "ival = " << ival << std::endl;
return 0;
}