64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
int *fun(void);
int main(void)
{
using namespace std;
int *b = fun();
putchar('\a'); // 加这句,它就灵不起来了
cout<<*b<<endl;
*b = *b;
cout<<*b<<endl;
}
int *fun(void)
{
int a = 4;
return &a;
}
#include "stdio.h"
#include<iostream>
using namespace std;
int *fun(void);
int main(void)
{
int *b = fun();
int temp=*b;
//没有*b=*b,那么*b的值会保持为4;
// cout<<*b<<endl; //调用cout后b成为真正是野指针
printf("%d %d %d\n",temp,*b,&b);
*b = *b;
printf("%d %d %d\n",temp,*b,&b);
cout<<*b<<endl;
// cout<<temp<<" "<<*b<<(int*)&b<<endl;
printf("%d %d %d\n",temp,*b,&b);
return 0;
}
int *fun(void)
{
int a = 4;
return &a;
}