pointer

pass by pointer

void fn ( int * copy) {
	copy = new int;
	*copy = 10;
}

int main() {
	int *x;
	fn(x);
	cout << *x; // Whats the output?
}

实际他的原理是这样的
int* x创建了一个pointer,然后把x pass到fn这个function
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Nick_kn/article/details/112982426