int a, float b; //为什么不报错??输出结果还不同?
int a, float b; //为什么不报错??输出结果还不同?int c; float d;
a = 0; b = 3.14;
c = 0; d = 3.14;
cout << a << " " << b << endl;
cout << c << " " << d << endl;
你用的是什么编译器?
#include <iostream>
using namespace std;
int main( void )
{
int a, float b;
int c; float d;
a = 0; b = 3.14;
c = 0; d = 3.14;
cout << a << " " << b << endl;
cout << c << " " << d << endl;
}
g++(测试用的是10.1.0版本)报错;
clang(测试用的是10.0.0版本)报错;
VC++(测试用的是16.6.2版本)报错。 你用的是什么编译器?
gcc、clang、vc++ 我都测试过了,都报错。 没法回帖? 回复 4# bruceteen
vc 6.0 这不是通用的教学编译器么?
实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。
实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。
实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。 warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
C4288 去查一下
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
页:
[1]
2