简体   繁体   English

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

[英]What is 1LL or 2LL in C and C++?

I was looking at some of the solutions in Google Code Jam and some people used this things that I had never seen before. 我正在查看Google Code Jam中的一些解决方案,有些人使用了我从未见过的东西。 For example, 例如,

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>

The LL makes the integer literal of type long long . LL使long long类型的整数文字变long long

So 2LL , is a 2 of type long long . 所以2LL ,是long long 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 int to be 32-bits, you shift beyond the size of the integer type -> undefined behavior). 仅使用文字1 ,(假设int为32位,您将超出整数类型的大小->未定义行为)。 With 1LL , you set the type to long long before hand and now it will properly return 2^40. 使用1LL ,您可以将类型设置为long long于手的时间,现在它将正确返回2 ^ 40。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM