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

青春壹個敷衍的年華 提交于 2019-11-27 00:14:35

问题


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,

2LL*r+1LL

What does 2LL and 1LL mean?

Their includes look like this:

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

or

#include <cmath>

回答1:


The LL makes the integer literal of type long long.

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

Without the LL, the literal would only be of type 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). With 1LL, you set the type to long long before hand and now it will properly return 2^40.



来源:https://stackoverflow.com/questions/16248221/what-is-1ll-or-2ll-in-c-and-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!