64,686
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int * add1(const int & a,const int &b)
{
int c=a+b;
cout < <"在函数add1的内部结果为" < <c < <endl;
int * pc = &c;
return pc;
}
void add2(const int &a, const & b)
{
char buffer[100]="abcdefg";
memset(buffer,0,100);
}
//哈哈,在编译这个函数的时候vc6.0给出了下面的警告:
//warning C4172: returning address of local variable or temporary
void main()
{
int a=1,b=2,*p;
cout < <"调用add1返回一个空悬指针\n";
p=add1(a,b);
add2(a,b);
cout < <"指针所指的值为" < <*p < <endl; //(1)
cout < <"指针所指的值发生改变 了吗?\n" < <(*p==3?"没有改变":"改变") < <endl; //(2)
}