C 和 C++ 中的 1LL 或 2LL 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16248221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:10:30  来源:igfitidea点击:

What is 1LL or 2LL in C and C++?

c++cmathlong-integercmath

提问by fersarr

I was looking at some of the solutions in Google Code Jam and some people used this things that I had never seen before. For example,

我在看 Google Code Jam 中的一些解决方案,有些人使用了我以前从未见过的东西。例如,

2LL*r+1LL

What does 2LL and 1LL mean?

2LL 和 1LL 是什么意思?

Their includes look like this:

它们的包含如下所示:

#include <math.h>
#include <algorithm>
#define _USE_MATH_DEFINES

or

或者

#include <cmath>

回答by Kyurem

The LLmakes the integer literal of type long long.

LL制式的整数文字long long

So 2LL, is a 2 of type long long.

所以2LL,是一个 2 类型long long

Without the LL, the literal would only be of type int.

如果没有LL,文字的类型就只有int

This matters when you're doing stuff like this:

当你做这样的事情时,这很重要:

1   << 40
1LL << 40

With just the literal 1, (assuming intto be 32-bits, you shift beyond the size of the integer type -> undefined behavior). With 1LL, you set the type to long longbefore hand and now it will properly return 2^40.

仅使用文字1, (假设int为 32 位,您将超出整数类型的大小 -> 未定义行为)。使用1LL,您将类型设置为long long之前,现在它将正确返回 2^40。