假设程序在具有UTF-16编码字符集的系统上运行.所以根据C++编程语言 - 第4页,第150页:
char可以保存机器字符集的字符.
→我认为char变量的大小是2字节.
但根据ISO/IEC 14882:2014:
sizeof(char),sizeof(signed char)并且sizeof(unsigned char)是1".
或者C++编程语言 - 第4页,第149页:
"[...],所以根据定义,char的大小是1"
→固定尺寸为1.
问题:上述这些语句之间是否存在冲突,或者sizeof(char) = 1只是默认(定义)值,并且实现定义取决于每个系统?
根据The C++ Programming Language - 4th,6.2.5节:
有三种浮点类型:float(单精度),double(双精度)和long double(扩展精度)
请参阅:http://en.wikipedia.org/wiki/Single-precision_floating-point_format
除非指数以全零存储,否则真有效数包括二进制点右侧的23个小数位和隐含的前导位(位于二进制点的左侧),值为1.因此,只有23个小数位的有效位出现在存储器格式中,但总精度是24位(相当于log10(224)≈7.225十进制数).
→浮点数的最大位数为7数字binary32 interchange format.(在计算机内存中占用4个字节(32位)的计算机数字格式)
当我在不同的编译器(如GCC,VC编译器)上进行测试时
→它总是6作为值输出.
看看float.h每个编译器
→我发现它6已修复.
题:
码:
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: digits10 << endl;
float f = -9999999;
cout.precision …Run Code Online (Sandbox Code Playgroud) 我已经在VS2013和Dev-C++上运行了这个代码但是当副本赋值没有返回任何实际应该的时候,编译器不会引发任何错误,请帮我解释一下.
#include <iostream>
using namespace std;
class sample
{
public:
sample()
{
cout << "X::X()" << endl;
}
sample(sample const &)
{
cout << "X::X( X const & )" << endl;
}
sample& operator=(sample const &)
{
cout << "X::operator=(X const &)" << endl;
}
};
sample f()
{
sample tmp;
return tmp;
}
int main()
{
int a;
sample x = f();
cin >> a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我改为:
sample x;
x = f();
Run Code Online (Sandbox Code Playgroud)
VS2013编译器会引发如下错误:错误1错误C4716:'sample :: operator =':必须返回值c:\ users\xxx\desktop\test\test\main.cpp …