指针的指针作用 int**

详解:“指向指针的指针”的作用和应用_清风徐来-CSDN博客_指向指针的指针的用法

主要作用:

1.获取在局部函数中申请的内存数据

#include <iostream>

#include "Memdect.h"
#include <map>
#include <vector>
using namespace std;

struct Test
{
	int num = 1;
	string name = "test";
};

void GetTest(Test ** pResul)
{
	Test* P = new Test();
	*pResul = P;
}

void GetResult(Test* pResul)
{
    Test* P = new Test();
    pResul = P;
}

int main(void)
{
	Test* p = nullptr;
	GetTest(&p);
	cout << "num is:" << p->num << endl;
	cout << "name is:" << p->name << endl;
	delete p;
	p = nullptr;
	Test* tp = nullptr;
	GetResult(tp);
	if (!tp)
		cout << "tp is not exist" << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38409301/article/details/121470858