Itʹs time we talk in detail about pointers, because we will be using them constantly throughout the rest of the book. You may already be familiar with some or all of the background information discussed in this chapter. If you arenʹt, study it carefully because your understanding of pointers will rest on this foundation.
是詳細讨論指針的時候了,因為在本書的剩餘部分,我們将會頻繁地使用指針。你可能已經熟悉了本章所讨論的部分或全部背景資訊。但是,如果你對此尚不熟悉,請認真學習,因為你對指針的了解将建立在這個基礎之上。
6.1 Memory and Addresses
As mentioned earlier, we can view the computerʹs memory as a row of houses on a long street. Each house is capable of holding data and is identified by a house number.
我在前面提到過,我們可以把計算機的記憶體看作是一條長街上的一排房屋。每座房子都可以容納資料,并通過一個房号來辨別。
This analogy is useful but limited. Computer memories are composed of millions of bits, each capable of holding either the value 0 or the value 1. This limited range of values is not terribly useful, so bits are usually grouped together and treated as a unit in order to store a wider range of values. Here is a picture of a few memory locations on a real machine.
這個比喻頗為有用,但也存在局限性。計算機的記憶體由數以億萬計的位(bit)組成,每個位可以容納值0或l。由于一個位所能表示的值的範圍太有限,是以單獨的位用處不大,通常許多位合成一組作為一個機關,這樣就可以存儲範圍較大的值。這裡有一幅圖,展示了現實機器中的一些記憶體位置。

Each of these locations is called a byte, and each contains as many bits as necessary to store a single character. On many modern machines, each byte contains eight bits,which can store unsigned integers from 0 to 255 or signed integers from ‐128 to 127.The previous diagram does not show the contents of the locations, though every location in memory always contains some value. Each byte is identified by an address,which is represented in the diagram by the numbers above each box.
這些位置的每一個都被稱為位元組( byte),每個位元組都包含了存儲一個字元所需要的位數。在許多現代的機器上,每個位元組包含8個位,可以存儲無符号值O至255,或有符号值-128至127。上面這張圖并沒有顯示這些位置的内容,但記憶體中的每個位置總是包含一些值。每個位元組通過位址來辨別,如上圖方框上面的數字所示。
To store even larger values, we take two or more bytes and treat them as if they were a single, larger unit of memory. For example, many machines store integers in words, each composed of two or four bytes. Here are the same memory locations, this time viewed as four‐byte words.
為了存儲更大的值,我們把兩個或更多個位元組合在一起作為一個更大的記憶體機關·例如,許多機器以字為機關存儲整數,每個字一般由2個或4個位元組組成。下面這張圖所表示的記憶體位置與上面這張圖相同,但這次它以4個位元組的字來表示。
Because they contain more bits, each word is capable of holding unsigned integers from 0 to 4,294,967,295 (232 – 1) or signed integers from –2,147,483,648 (–231) to 2,147,483,647 (231 – 1).
由于它們包含了更多的位,每個字可以容納的無符号整數的範圍是從0至4294967295(232 – 1),可以容納的有符号整數的範圍是從-2147483648(–231)至2147483647(231 – 1)。
Note that even though a word contains four bytes, it has only one address. It is machine‐dependent whether the address of a word is the address of the leftmost byte in the word or the rightmost. Boundary alignment is another hardware issue. On machines with this requirement, integers can only begin with certain bytes, usually those whose addresses are multiples of two or four. But these issues are the hardware designerʹs problem, and they rarely affect C programmers. We are interested in only two issues:
注意,盡管一個字包含了4個位元組,它仍然隻有一個位址。至于它的位址是它最左邊那個位元組的位置還是最右邊那個位元組的位置,不同的機器有不同的規定。另一個需要注意的硬體事項是邊界對齊(boundary alignment)。在要求邊界對齊的機器上,整型值存儲的起始位置隻能是某些特定的位元組,通常是2或4的倍數。但這些問題是硬體設計者的事情,它們很少影響C程式員。我們隻對兩件事情感興趣
1. Each location in memory is identified by a unique address.
記憶體中的每個位置由一個獨一無二的位址辨別。
2. Each location in memory contains a value.
記憶體中的每個位置都包含一個值。