若将第10行代码替换为 p = &b;程序依然可以访问p所指内容,所以此段代码无法证明大括号内的内存是否销毁或保留
#include <stdio.h>
#include <iostream>
int main()
{
int* p = nullptr;
{
int b = 20;
p = &b;
}
*p = 4;
printf(" *p is %d\n", *p);
system("pause");
return 0;
}
#include <stdio.h>
#include <iostream>
int main()
{
int* p = nullptr;
{
int b = 20;
p = &b;
}
*p = 4;
printf(" *p is %d\n", *p);
system("pause");
return 0;
}
2023-08-03
举报