What is the size (in bytes) for each of the literals '7', 7.0, “7”?
我的任务是回答这个问题,老实说,我不知道如何找到这些字节的大小。有人可以指出我正确的方向吗?
最佳答案
一种方法是使用 sizeof 运算符。
例如,
#include <iostream>
#include <math.h>
int main(int argc, char **argv)
{
std::cout << "size of char 6 is " << sizeof('6') << std::endl;
std::cout << "size of float 6.0 is " << sizeof(6.0) << std::endl;
std::cout << "size of string 6 is " << sizeof("6") << std::endl;
return 0;
}
关于c++ - 文字的字节大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109285/