gpt4 book ai didi

c++ - 为什么这个指针在 Visual Studio 2012 Professional 中仍然有效?

转载 作者:行者123 更新时间:2023-11-28 00:18:47 25 4
gpt4 key购买 nike

<分区>

这是我的代码

#include<iostream>

using namespace std;

int *f1(int x) {
return &x;
}

void f2(int a, int b, int c){

cout<<a<<endl;
}

int main() {

cout<<"hari Hari"<<endl;

int *x;
x = f1(90);
f2(3,45,2);

cout<<*x<<endl;

system("PAUSE");
}

现在 f1 返回指向堆栈的指针,假设它被 f2 覆盖,预期的输出应该看起来像这样“哈里哈里3个3个“但实际上我得到了正确的答案,我的实际输出是,“哈里哈里3个90后“我不明白为什么它不覆盖 f1 函数的 'x' 的值。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com