- 博客(133)
- 资源 (1)
- 收藏
- 关注
翻译 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
570
翻译 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
477
翻译 Pointers on C——12 Using Structures and Pointers.2
12.2.1 Inserting into a Singly Linked List How 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
345
翻译 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
300
翻译 Pointers on C——11 Dynamic Memory Allocation.6
11.7 Summary When 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
261
翻译 Pointers on C——11 Dynamic Memory Allocation.5
11.6 Memory Allocation Examples A 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
412
翻译 Pointers on C——11 Dynamic Memory Allocation.4
11.5.1 Memory Leaks Dynamically 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
215
翻译 Pointers on C——11 Dynamic Memory Allocation.3
11.5 Common Dynamic Memory Errors There 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
342
翻译 Pointers on C——11 Dynamic Memory Allocation.2
11.3 Calloc and Realloc There are two additional memory allocation functions, calloc and realloc. Their prototypes are shown below. 另外还有两个内存分配函数, calloc 和realloc。 它们的原型如下所示: voi
2017-09-10 10:38:05
259
翻译 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
739
翻译 Pointers on C——10 Structures and Unions.16
10.6.2 Initializing Unions A 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
244
翻译 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
248
翻译 Pointers on C——10 Structures and Unions.14
10.6 Unions A 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
203
翻译 Pointers on C——10 Structures and Unions.13
10.5 Bit Fields One 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
273
翻译 Pointers on C——10 Structures and Unions.12
10.4 Structures as Function Arguments A 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
231
翻译 Pointers on C——10 Structures and Unions.11
10.3 Structure Storage Allocation How 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
195
翻译 Pointers on C——10 Structures and Unions.10
10.2.5 Accessing a Pointer Member The 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
201
翻译 Pointers on C——10 Structures and Unions.9
10.2.4 Accessing a Nested Structure To 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
190
翻译 Pointers on C——10 Structures and Unions.8
10.2.3 Accessing Structure Members Now letʹs look at the arrow operator. The R‐value of the expression px->a is The ‐> operator applies indirection to px (indicated by the
2017-09-09 09:42:23
233
翻译 Pointers on C——10 Structures and Unions.7
10.2.1 Accessing the Pointer Letʹ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
302
翻译 Pointers on C——10 Structures and Unions.6
10.2 Structures, Pointers, and Members The 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
182
翻译 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
210
翻译 Pointers on C——10 Structures and Unions.4
10.1.4 Indirect Member Access How 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
218
翻译 Pointers on C——10 Structures and Unions.3
10.1.2 Structure Members In 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
228
翻译 Pointers on C——10 Structures and Unions.2
10.1.1 Structure Declarations Structures 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
178
翻译 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
205
翻译 Pointers on C——9 Strings, Characters, and Bytes.11
9.10 Summary A 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
196
翻译 Pointers on C——9 Strings, Characters, and Bytes.10
9.9 Memory Operations By 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
169
翻译 Pointers on C——9 Strings, Characters, and Bytes.9
9.7 Error Messages When 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
176
翻译 Pointers on C——9 Strings, Characters, and Bytes.8
9.6.2 Finding Tokens A string often contains several individual parts that are somehow separated from each other. To process these parts one at a time, you must first extract them from the string
2017-09-08 08:54:19
172
翻译 Pointers on C——9 Strings, Characters, and Bytes.7
9.6 Advanced String Searching 高级字符串查找 The next group of functions simplify the location and extraction of individual substrings from a string. 接下来的一组函数简化了从一个字符串中查找和抽取一个子串的过程。
2017-09-08 08:53:50
219
翻译 Pointers on C——9 Strings, Characters, and Bytes.6
9.5 Basic String Searching There are many functions in the library that search strings in various ways. This wide variety of tools gives the C programmer great flexibility. 标准库中存在许多函数,它们用各
2017-09-08 08:53:20
224
翻译 Pointers on C——9 Strings, Characters, and Bytes.5
9.4 Length-Restricted String Functions The library includes several functions that deal with strings in a different way. This group of functions takes an explicit length argument that limit
2017-09-07 09:07:28
227
翻译 Pointers on C——9 Strings, Characters, and Bytes.4
9.3.2 Concatenating Strings To append (concatenate) one string to the end of another, strcat is used prototype is: 要想把一个字符串添加(连接〉到另一个字符串的后面,你可以使用strcat 函数。它的原型如下: char *strcat(
2017-09-07 09:05:36
221
翻译 Pointers on C——9 Strings, Characters, and Bytes.3
9.3 Unrestricted String Functions The most commonly used string functions are ʺunrestricted,ʺ meaning that they determine the length of their string arguments solely by looking for the term
2017-09-07 09:04:58
269
翻译 Pointers on C——9 Strings, Characters, and Bytes.2
9.2 String Length The length of a string is the number of characters it contains. The length is easily computed by counting the characters, as is done in Program 9.1. This implementation illustra
2017-09-07 09:04:31
238
翻译 Pointers on C——9 Strings, Characters, and Bytes.1
Strings are an important type of data, yet C does not have an explicit string data type because strings are stored in character arrays or as string literals. Literals are appropriate for strings tha
2017-09-07 09:03:39
142
翻译 Pointers on C——8 Arrays.22
8.4 Summary The value of an array name in most expressions is a pointer to the first element of the array. There are only two exceptions to this rule, sizeof returns the number of bytes i
2017-09-07 09:01:31
313
翻译 Pointers on C——8 Arrays.21
8.3 Arrays of Pointers 指针数组 Aside from its type, a pointer variable is like any other variable. Just as you can create arrays of integers, you can also declare arrays of pointers. Here i
2017-09-07 09:00:57
242
翻译 Pointers on C——8 Arrays.20
8.2.7 Automatic Array Sizing With multidimensional arrays, only the first dimensional of the array can be implied by the initializer list. The remaining ones are needed so that the compiler can d
2017-09-07 09:00:19
150
protues智能车
2014-11-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅