C&Cpp未初始化全局变量与局部变量结果
gcc 版本
GCC version: 11.2.0
以下代码输出GCC版本信息
#include <iostream>
using namespace std;
int main()
{
cout << "GCC version: " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << endl;
return 0;
}
在命令行中输入gcc --version
显示更详细的版本信息
gcc.exe (x86_64-posix-seh-rev3, Built by MinGW-W64 project) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
Cpp演示
#include <iostream>
using namespace std;
int a;
int main()
{
int b;
/* 全局变量与局部变量如果不加指定 将会自动初始化为零 */
/* 但不建议这样使用 */
cout << "a = " << a << endl;
cout << "b = " << b << endl;
return 0;
}
输出结果展示
a = 0
b = 0
C语言演示
#include <stdio.h>
int a;
int main()
{
int b;
printf("a = %d\n", a);
printf("b = %d", b);
return 0;
}
输出结果展示
a = 0
b = 0