C++语言开发示例:07. 返回指针
rtnpointer.cpp
#include <iostream>
#include <cstring>
int *retNoNew();
int *retNew();
int main()
{
using namespace std;
int *n1 = retNoNew();
int *n2 = retNew();
cout << "n1 = " << n1 << "\nn2 = " << n2 << endl;
delete n1;
delete n2;
}
int *retNoNew()
{
int n = 3;
return &n;
}
int *retNew()
{
int *n = new int;
*n = 4;
return n;
} 最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: C++语言开发示例:07. 返回指针
推荐阅读
评论 (0)
发表评论
昵称:加载中...
暂无评论,快来发表第一条评论吧!