小编oja*_*360的帖子

无法理解C和C++中静态的行为

#include <stdio.h>

int main()
{
    goto lb;
    static int a=5;

lb:
    goto b;
    int b=6;

b:
    printf("%d %d",a,b);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用".c"文件扩展名保存此代码时,它运行良好,输出为5,后跟"垃圾"值.

但是,在C++中,它会导致错误.我无法理解为什么会有错误.你能告诉我怎么解决吗?

c c++

-5
推荐指数
1
解决办法
112
查看次数

标签 统计

c ×1

c++ ×1