设为首页 加入收藏

TOP

2.1 Primitive Built-in Types (7)
2013-10-07 16:15:19 来源: 作者: 【 】 浏览:81
Tags:2.1 Primitive Built-in Types

When youwrite a long literal, use the uppercase L; the lowercase letter l is too easily mistaken for the digit 1.

We can independently specify the signedness and size of an integral literal. If the suffix contains a U, then the literal has an unsigned type, so a decimal, octal, or hexadecimal literal with a U suffix has the smallest type of unsigned int, unsigned long, or unsigned long long in which the literal’s value fits. If the suffix contains an L, then the literal’s type will be at least long; if the suffix contains LL, then the literal’s type will be either long long or unsigned long long.
We can combine U with either L or LL. For example, a literal with a suffix of UL will be either unsigned long or unsigned long long, depending on whether its value fits in unsigned long.

Boolean and Pointer Literals

The words true and false are literals of type bool:

bool test = false;

The word nullptr is a pointer literal. We’ll have more to say about pointers and nullptr in § 2.3.2 (p. 52).

EXERCISES SECTION 2.1.3

Exercise 2.5: Determine the type of each of the following literals. Explain the differences among the literals in each of the four examples:

(a) ’a’, L’a’, "a", L"a"

(b) 10, 10u, 10L, 10uL, 012, 0xC

(c) 3.14, 3.14f, 3.14L

(d) 10, 10u, 10., 10e-2

Exercise 2.6: What, if any, are the differences between the following definitions:

int month = 9, day = 7;
int month = 09, day = 07;

Exercise 2.7: What values do these literals represent What type does each have

(a) "Who goes with F\145rgus \012"

(b) 3.14e1L

(c) 1024f

(d) 3.14L

Exercise 2.8: Using escape sequences, write a programto print 2M followed by a newline. Modify the program to print 2, then a tab, then an M, followed by a newline.

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2.1 Primitive Built-in Types (6) 下一篇2.2 Variables (1)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)