惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
博客园 - 司徒正美
雷峰网
雷峰网
L
LINUX DO - 最新话题
博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
The Last Watchdog
The Last Watchdog
V2EX - 技术
V2EX - 技术
S
Security Affairs
有赞技术团队
有赞技术团队
月光博客
月光博客
T
Threatpost
T
Tor Project blog
O
OpenAI News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
V2EX
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
博客园 - 三生石上(FineUI控件)
D
Docker
AWS News Blog
AWS News Blog
AI
AI
P
Proofpoint News Feed
K
Kaspersky official blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Securelist
F
Fortinet All Blogs
F
Full Disclosure
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Palo Alto Networks Blog
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog

博客园 - 撬棍

【.Net】2、8、16进制转换 【.Net】执行CMD命令 【.Net】获取随机数函数 【.Net】注册程序开机启动 【.Net】把窗体“钉”到桌面上 【.Net】多语言查看MSDN 【.Net】 显示星期字符串 【.Net】 判断时间字符串正确性 【.Net】 实现窗口拖动 【.Net】 Winform 单例运行实例 [C++]函数返回值 [C++]数组参数 [C++]const的指针使用 [VBA]Excel输出utf-8编码格式文件 使用WideCharToMultiByte 【C++】split [C语言学习]之打印万年历 - 撬棍 - 博客园 [VB6.0]让程序在任务列表和资源管理器“隐身” [InstallShield]FindAllFiles与SetFileInfo配合实现文件加多文件属性设置 [VB]修改注册表让程序开机自动运行 - 撬棍 - 博客园
[C++]指针类型出参
撬棍 · 2013-03-19 · via 博客园 - 撬棍

1.以下函数无法将指针出参带出,因为修改的只是pi形参的值,实参值(main::pi)没有被修改,和传入一个int型原则上是没有区别的。

int val = 10;
void foobar( int *pi ) 
{
    pi = &val;
    return;
}

void main()
{
    int *pi = 0;
    foobar(pi);
    if (pi == 0)
    {
        std::cout << "pi is NULL.";
    }
    else
    {
        std::cout << "pi is:" << *pi;
    }
    return;
}

pi is NULL.请按任意键继续. . . 

2、方法可以是传入指针的引用,此时并没有创建形参pi,直接使用实参,和传入一个int型引用原则上是没有区别的。

int val = 10;
void foobar(int *&pi) 
{
    pi = &val;
    return;
}

void main()
{
    int *pi = 0;
    foobar(pi);
    if (pi == 0)
    {
        std::cout << "pi is NULL.";
    }
    else
    {
        std::cout << "pi is:" << pi;
    }
    return ;
}

pi is:00412004请按任意键继续. . .

3、传入指针的指针,这个稍稍有些难理解,修改的是传入的指针的指向指针的值,所有可以带出。

int val = 10;
void foobar(int **ppi) 
{
    *ppi = &val;
    return;
}

void main()
{
    int *pi = 0;
    int **ppi = &pi;
    foobar(ppi);
    if (*ppi == 0)
    {
        std::cout << "pi is NULL.";
    }
    else
    {
        std::cout << "pi is:" << *ppi;
    }
    return ;
}

pi is:00412004请按任意键继续. . .