2.2 Literal Constants (2)

2013-10-07 15:25:00 · 作者: · 浏览: 69

Rules for Integer Literals

We can write a literal integer constant using one of three notations: decimal, octal, or hexadecimal. These notations, of course, do not change the bit representation of the value, which is always binary. For example, we can write the value 20 in any of the following three ways:

  1. 20 // decimal  
  2. 024 // octal  
  3. 0x14 // hexadecimal 

Literal integer constants that begin with a leading 0 (zero) are interpreted as octal; those that begin with either 0x or 0X are interpreted as hexadecimal.

根据语法来看,0 其实是个八进制数。

By default, the type of a literal integer constant is either int or long. The
precise type depends on the value of the literal—values that fit in an int are type

EXERCISES SECTION 2.1.2

Exercise 2.1: What is the difference between an int, a long, and a short value

Exercise 2.2: What is the difference between an unsigned and a signed type

Exercise 2.3: If a short on a given machine has 16 bits then what is the largest number that can be assigned to a short To an unsigned short

Exercise 2.4: What value is assigned if we assign 100,000 to a 16-bit unsigned short What value is assigned if we assign 100,000 to a plain 16-bit short

Exercise 2.5: What is the difference between a float and a double

Exercise 2.6: To calculate amortgage payment, what types would you use for the rate,principal, and payment Explain why you selected each type.