![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Pointers on C
ai_albert
这个作者很懒,什么都没留下…
展开
-
Pointers on C——9 Strings, Characters, and Bytes.9
9.7 Error MessagesWhen calls are made to the operating system to perform functions, such as opening files, errors that occur are reported by setting an external integer variable called errno to翻译 2017-09-08 08:54:50 · 117 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.10
10.2.5 Accessing a Pointer MemberThe expression px->d gives the result you would expect—its R‐value is 0, and its L-value is the location itself. The expression *px->d is more interesting. Her翻译 2017-09-09 09:43:20 · 143 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.11
10.3 Structure Storage AllocationHow are structures actually stored in memory? The diagrams in the previous examples imply that structures contain a lot of empty space. This picture is not entir翻译 2017-09-09 09:43:57 · 142 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.12
10.4 Structures as Function ArgumentsA structure variable is a scalar and can be used wherever any other scalar can be used.Thus it is legal to pass a structure as an argument to a functio翻译 2017-09-09 09:44:24 · 151 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.13
10.5 Bit FieldsOne last thing to mention about structures is their capability for implementing bit fields. A bit field is declared exactly like a structure except that its members are fields of翻译 2017-09-09 09:44:58 · 186 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.14
10.6 UnionsA union is a different animal altogether. A union is declared like a structure but doesnʹt work like a structure. All of the members of a union refer to the same location(s)in mem翻译 2017-09-09 09:45:29 · 149 阅读 · 0 评论 -
Pointers on C——12 Using Structures and Pointers.3
Debugging the Insert Function调试插入函数Unfortunately, the insert function is incorrect. Try inserting the value 20 into the list and you will see one problem: the while loop runs off the e翻译 2017-09-18 08:58:20 · 389 阅读 · 0 评论 -
Pointers on C——12 Using Structures and Pointers.4
Optimizing the Insert Function二、优化插入函数It appears that inserting a node at the beginning of the list must be a special case. After all, the pointer that must be adjusted to insert the first n翻译 2017-09-18 08:59:04 · 478 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.15
10.6.1 Variant Records变体记录Letʹs examine an example that implements what Pascal and Modula call a variant record. Conceptually, this is the same situation we just discussed—a particular area翻译 2017-09-10 10:35:04 · 184 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.9
10.2.4 Accessing a Nested StructureTo access the member c, which is a structure, use the expression px->c. Its R‐value is the entire structure.为了访问本身也是结构的成员。我们可以使用表达式px->c 。它的左值是整个结构。翻译 2017-09-09 09:42:51 · 136 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.8
10.2.3 Accessing Structure MembersNow letʹs look at the arrow operator. The R‐value of the expression px->a isThe ‐> operator applies indirection to px (indicated by the翻译 2017-09-09 09:42:23 · 159 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.7
10.2.1 Accessing the PointerLetʹs begin with the pointer variable. The R‐value of the expression px is:让我们从指针变量开始。表达式px 的右值是:px is a pointer variable but there isnʹt any in翻译 2017-09-09 09:41:50 · 154 阅读 · 0 评论 -
Pointers on C——9 Strings, Characters, and Bytes.10
9.9 Memory OperationsBy definition, a string is terminated with a NUL byte, so strings may not contain any NULs. However, it is not uncommon for nonstring data to contain zeros. You cannot use t翻译 2017-09-08 08:55:17 · 123 阅读 · 0 评论 -
Pointers on C——9 Strings, Characters, and Bytes.11
9.10 SummaryA string is a sequence of zero or more characters. The sequence is terminated by a NUL byte. The length of a string is the number of characters it contains. The standard library pro翻译 2017-09-08 08:55:51 · 144 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.1
Data frequently exists in groups. For example, an employer must keep track of the name, age, and salary of each employee. Accessing these values is simplified if they can be stored together. However翻译 2017-09-08 08:56:26 · 152 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.2
10.1.1 Structure DeclarationsStructures are declared by listing the members that they will contain. This list includes the type and the name of each member.在声明结构时,必须列出它包含的所有成员。这个列表包括每个成员的类型和名字翻译 2017-09-08 08:56:53 · 127 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.3
10.1.2 Structure MembersIn the examples so far, I have used only simple types for members. But any kind of variable that can be declared outside of a structure may also be used as a structure me翻译 2017-09-08 08:57:29 · 168 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.4
10.1.4 Indirect Member AccessHow do you access the members of a structure if all you have is a pointer to it? The first step is to apply indirection to the pointer, which takes you to the翻译 2017-09-08 08:58:39 · 166 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.5
10.1.5 Self-Referential Structures结构的自引用Is it legal for a structure to contain a member that is the same type as the structure?Here is an example to illustrate this idea.在一个结构内部包含一个类型为翻译 2017-09-09 09:40:29 · 151 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.6
10.2 Structures, Pointers, and MembersThe operators for accessing structures and their members directly and through pointers are quite simple, but they can become confusing when applied in翻译 2017-09-09 09:41:14 · 133 阅读 · 0 评论 -
Pointers on C——10 Structures and Unions.16
10.6.2 Initializing UnionsA union variable can be initialized, but the value must appropriate for the type of the first member of the union, and it must be enclosed in braces. For example,联翻译 2017-09-10 10:35:40 · 178 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.1
The elements of an array are stored in contiguous locations in memory. When an array is declared, its memory is allocated at compile time. However, you can also allocate the memory at runtime with d翻译 2017-09-10 10:36:43 · 626 阅读 · 0 评论 -
Pointers on C——6 Pointers.5
6.5 Uninitialized and Illegal PointerThe code fragment below illustrates a very common error:下面这个代码段说明了一个极为常见的错误:int *a;...*a = 12;The declaration creates a pointe翻译 2017-09-03 00:12:36 · 115 阅读 · 0 评论 -
Pointers on C——6 Pointers.6
6.6 The Null PointerThe Standard defines a NULL pointer as a pointer value that does not point to anything at all. To make a pointer variable NULL you assign it the value zero, and to test w翻译 2017-09-03 00:13:21 · 124 阅读 · 0 评论 -
Pointers on C——6 Pointers.7
6.7 Pointers, Indirection, and L-valuesCan expressions involving pointers be used as L‐values? If so, which ones? A quick check of the precedence chart in Table 5.1 confirms that the operand ne翻译 2017-09-03 00:13:58 · 177 阅读 · 0 评论 -
Pointers on C——6 Pointers.8
6.8 Pointers, Indirection, and VariablesIf you think youʹve mastered pointers, take a look at this expression and see if you can figure out what it does如果你自以为己经精通了指针,请看一下这个表达式,看看你是否明白它的意思。翻译 2017-09-03 00:14:38 · 125 阅读 · 0 评论 -
Pointers on C——6 Pointers.9
6.9 Pointer ConstantsLetʹs examine another expression. Assuming that the variable a is stored at location 100, what does this statement do?让我们来分析另外一个表达式。假定变量a 存储于位置100 ,下面这条语旬的作用是什么?翻译 2017-09-03 00:15:25 · 105 阅读 · 0 评论 -
Pointers on C——6 Pointers.10
6.10 Pointers to PointersWe will spend only a brief moment here on an example that suggests topics to come.Consider these declarations:这里我们再稍微花点时间来看一个例子,揭开这个即将开始的主题的序幕。考虑下面这些声明:in翻译 2017-09-03 00:16:07 · 114 阅读 · 0 评论 -
Pointers on C——6 Pointers.11
6.11 Pointer ExpressionsNow letʹs take a look at a variety of pointer expressions and see how they are evaluated when used both as R‐values and L‐values. Some of these expressions are commonly翻译 2017-09-03 00:16:48 · 181 阅读 · 0 评论 -
Pointers on C——6 Pointers.12
6.12 ExamplesHere are some sample programs to illustrate a few common pointer expressions.Program 6.1 computes the length of a string. You should never have to write this function because the l翻译 2017-09-03 00:17:31 · 163 阅读 · 0 评论 -
Pointers on C——6 Pointers.4
6.4 Indirection OperatorThe process of following a pointer to the location to which it points is called indirection or dereferencing the pointer. The operator that performs indirection is翻译 2017-09-02 08:36:32 · 158 阅读 · 0 评论 -
Pointers on C——6 Pointers.3
6.3 Contents of a Pointer VariableGetting back to pointers, letʹs look at the declarations for the variables d and e. They are both declared as pointers, and they are initialized with the addres翻译 2017-09-02 08:35:13 · 179 阅读 · 0 评论 -
Pointers on C——6 Pointers.2
6.1.1 Address Versus ContentsHere is another example, this time showing the contents of five words in memory.这里有另外一个例子,这次它显示了内存中5个字的内容Five integer values are shown, each i翻译 2017-09-02 08:34:24 · 144 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.2
11.3 Calloc and ReallocThere are two additional memory allocation functions, calloc and realloc. Their prototypes are shown below.另外还有两个内存分配函数, calloc 和realloc。 它们的原型如下所示:voi翻译 2017-09-10 10:38:05 · 194 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.3
11.5 Common Dynamic Memory ErrorsThere are many errors that can occur in programs that use dynamic memory allocation. These include dereferencing NULL pointers, going outside die bounds of t翻译 2017-09-10 10:38:53 · 256 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.4
11.5.1 Memory LeaksDynamically allocated memory should be freed when it is no longer needed so that it can be reused later for other purposes. Allocating memory but not freeing it later ca翻译 2017-09-10 10:39:42 · 158 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.5
11.6 Memory Allocation ExamplesA common use for dynamic memory allocation is obtaining space for arrays whose sizes are not known until run time. Program 11.2 reads a list of integers, sor翻译 2017-09-10 10:40:28 · 327 阅读 · 0 评论 -
Pointers on C——11 Dynamic Memory Allocation.6
11.7 SummaryWhen an array is declared, its size must be known at compile time. Dynamic allocation allows a program to create space for an array whose size isnʹt known until runtime.当数组翻译 2017-09-10 10:42:14 · 205 阅读 · 0 评论 -
Pointers on C——12 Using Structures and Pointers.1
You can create powerful data structures by combining structures and pointers. In this chapter we take a closer look at some techniques for using structures and pointers.We spend a lot of time with a翻译 2017-09-10 10:42:53 · 223 阅读 · 0 评论 -
Pointers on C——12 Using Structures and Pointers.2
12.2.1 Inserting into a Singly Linked ListHow would we insert a new node into an ordered singly linked list? Suppose we had a new value, say 12, to insert into the previous list. Conceptually th翻译 2017-09-10 10:44:26 · 261 阅读 · 0 评论