【发布时间】:2021-04-01 21:55:09
【问题描述】:
我正在使用此操作函数来获取指针地址,但它返回任何其他内容。
#include<iostream>
using namespace std;
int *manipulate( int &b) {
int *a=&b;
cout<<&a<<" "<<&b<<" "; // why memory add of 'a' and 'b' different ?
return a; // is it returing pointer which stores address of 'b' ?
}
int main() {
int x=44;
cout<<&x<<" "; // gives memory address of x;
int *ptr=&x;
cout<<ptr<<" "; // gives mem address of x;
int &l=x;
cout<<&l<<" "; // gives memory add of x;
int *c=manipulate(x); //storing returned pointer
cout<<&c; // why address of 'c' different to that of returned pointer?
return 0;
}
【问题讨论】:
标签: c++ pointers memory function-pointers memory-address