指针的指针作用 int**
程序员文章站
2024-03-07 15:53:33
...
详解:“指向指针的指针”的作用和应用_清风徐来-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;
}
上一篇: 【C语言】对指针的深入理解