首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >0LL或0x0UL是什么意思?

0LL或0x0UL是什么意思?
EN

Stack Overflow用户
提问于 2011-08-12 05:48:21
回答 6查看 107.9K关注 0票数 28

我正在阅读Google教程,并在常量部分中看到了这一点:

没有像0LL或0x0UL这样的常量

我试图做谷歌搜索,但所有出现的情况是,人们使用这些常量,但没有解释他们的意思。0x应该启动十六进制文字,但这些字符不可能以十六进制数表示。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2011-08-12 05:50:27

这些是C和C++中的常量。后缀LL表示常量是long long类型,UL表示unsigned long

一般来说,每个Ll代表一个long,每个Uu代表一个unsigned。因此,例如。

代码语言:javascript
运行
复制
1uLL

表示类型为unsigned long long的常量1。

这也适用于浮点数:

代码语言:javascript
运行
复制
1.0f    // of type 'float'
1.0     // of type 'double'
1.0L    // of type 'long double'

以及字符串和字符,但它们是前缀:

代码语言:javascript
运行
复制
 'A'   // of type 'char'
L'A'   // of type 'wchar_t'
u'A'   // of type 'char16_t' (C++0x only)
U'A'   // of type 'char32_t' (C++0x only)

在C和C++中,整数常量是使用它们的原始类型计算的,这可能会由于整数溢出而导致错误:

代码语言:javascript
运行
复制
long long nanosec_wrong = 1000000000 * 600;
// ^ you'll get '-1295421440' since the constants are of type 'int'
//   which is usually only 32-bit long, not big enough to hold the result.

long long nanosec_correct = 1000000000LL * 600;
// ^ you'll correctly get '600000000000' with this

int secs = 600;
long long nanosec_2 = 1000000000LL * secs;
// ^ use the '1000000000LL' to ensure the multiplication is done as 'long long's.

在Google中,所有整数都被计算为大整数(不发生截断),

代码语言:javascript
运行
复制
    var nanosec_correct int64 = 1000000000 * 600

也没有"常用算术推广

代码语言:javascript
运行
复制
    var b int32 = 600
    var a int64 = 1000000000 * b
    // ^ cannot use 1000000000 * b (type int32) as type int64 in assignment

所以后缀是不必要的。

票数 43
EN

Stack Overflow用户

发布于 2011-08-12 05:52:20

有几种不同的基本数字类型,字母区分它们:

代码语言:javascript
运行
复制
0   // normal number is interpreted as int
0L  // ending with 'L' makes it a long
0LL // ending with 'LL' makes it long long
0UL // unsigned long

0.0  // decimal point makes it a double
0.0f // 'f' makes it a float
票数 11
EN

Stack Overflow用户

发布于 2011-08-12 05:49:54

0LL是一个长的零。

0x0UL是一个无符号长零,用十六进制表示法表示。0x0UL == 0UL.

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7036056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档