Đang chuẩn bị liên kết để tải về tài liệu:
Chapter 4 - Pointers and Strings
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Pointers and Strings the study of strings is useful to further tie in the relationship between pointers and arrays. It also makes it easy to illustrate how some of the standard C string functions can be implemented. Finally it illustrates how and when pointers can and should be passed to functions. | Chapter 5 - Pointers and Strings Outline 5.1 Introduction 5.2 Pointer Variable Declarations and Initialization 5.3 Pointer Operators 5.4 Calling Functions by Reference 5.5 Using const with Pointers 5.6 Bubble Sort Using Pass-by-Reference 5.7 Pointer Expressions and Pointer Arithmetic 5.8 Relationship Between Pointers and Arrays 5.9 Arrays of Pointers 5.10 Case Study: Card Shuffling and Dealing Simulation 5.11 Function Pointers 5.12 Introduction to Character and String Processing 5.12.1 Fundamentals of Characters and Strings 5.12.2 String Manipulation Functions of the String- Handling Library 5.1 Introduction Pointers Powerful, but difficult to master Simulate pass-by-reference Close relationship with arrays and strings 5.2 Pointer Variable Declarations and Initialization Pointer variables Contain memory addresses as values Normally, variable contains specific value (direct reference) Pointers contain address of variable that has specific value (indirect reference) . | Chapter 5 - Pointers and Strings Outline 5.1 Introduction 5.2 Pointer Variable Declarations and Initialization 5.3 Pointer Operators 5.4 Calling Functions by Reference 5.5 Using const with Pointers 5.6 Bubble Sort Using Pass-by-Reference 5.7 Pointer Expressions and Pointer Arithmetic 5.8 Relationship Between Pointers and Arrays 5.9 Arrays of Pointers 5.10 Case Study: Card Shuffling and Dealing Simulation 5.11 Function Pointers 5.12 Introduction to Character and String Processing 5.12.1 Fundamentals of Characters and Strings 5.12.2 String Manipulation Functions of the String- Handling Library 5.1 Introduction Pointers Powerful, but difficult to master Simulate pass-by-reference Close relationship with arrays and strings 5.2 Pointer Variable Declarations and Initialization Pointer variables Contain memory addresses as values Normally, variable contains specific value (direct reference) Pointers contain address of variable that has specific value (indirect reference) Indirection Referencing value through pointer Pointer declarations * indicates variable is pointer int *myPtr; declares pointer to int, pointer of type int * Multiple pointers require multiple asterisks int *myPtr1, *myPtr2; count 7 countPtr count 7 5.2 Pointer Variable Declarations and Initialization Can declare pointers to any data type Pointer initialization Initialized to 0, NULL, or address 0 or NULL points to nothing 5.3 Pointer Operators & (address operator) Returns memory address of its operand Example int y = 5; int *yPtr; yPtr = &y; // yPtr gets address of y yPtr “points to” y yPtr y 5 yptr 500000 600000 y 600000 5 address of y is value of yptr 5.3 Pointer Operators * (indirection/dereferencing operator) Returns synonym for object its pointer operand points to *yPtr returns y (because yPtr points to y). dereferenced pointer is lvalue *yptr = 9; // assigns 9 to y * and & are inverses of each other fig05_04.cpp (1 of 2) 1 // Fig. 5.4: fig05_04.cpp 2 // Using the & and