在某些变量初始化中,"l"是什么意思 - C++

Ous*_*ssa 0 c++ variables initialization declaration long-integer

在一些变量初始化中"l"的含义是什么?例如:

#define maxpossible     (1000000000L)
double A = 1L;
double B = 999999999l;
Run Code Online (Sandbox Code Playgroud)

"L"和"l"之间有区别吗?

Sha*_*our 5

这是一个后缀类型说明符,用于AB您可以阅读更多有关浮点文字在这里.简短的回答是,Ll都表示long double.因为maxpossible你可以在这里阅读整数文字L指出long.

编辑

正如Mike Seymour所指出的那样,所有的文字都是integer文字.这只是表明你不理智的时候检查你的答案,你会说错了.一个简单的健全检查将如下:

#include <iostream>
#include <typeinfo>

int main()
{
    std::cout << typeid( decltype( 1L ) ).name() << std::endl ;
    std::cout << typeid( decltype( 999999999l ) ).name() << std::endl ;
    std::cout << typeid( decltype( 1000000000L ) ).name() << std::endl ;
}
Run Code Online (Sandbox Code Playgroud)

这给了我l每一个,并通过运行c++filt -t给我long.什么会使文字浮点文字?要么:

  • 包含小数点的数字
  • 例如,使用指数表示法的数字 4e2

例如:

std::cout << typeid( decltype( .1l ) ).name() << std::endl ;
std::cout << typeid( decltype( 1e2L ) ).name() << std::endl ;
Run Code Online (Sandbox Code Playgroud)

这给了我e两个案例和运行通过c++filt -t给我long double.