Chapter 4 - Pointers and Strings

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 Introduction Pointer Variable Declarations and Initialization Pointer Operators Calling Functions by Reference Using const with Pointers Bubble Sort Using Pass-by-Reference Pointer Expressions and Pointer Arithmetic Relationship Between Pointers and Arrays Arrays of Pointers Case Study: Card Shuffling and Dealing Simulation Function Pointers Introduction to Character and String Processing Fundamentals of Characters and Strings String Manipulation Functions of the String- Handling Library Introduction Pointers Powerful, but difficult to master Simulate pass-by-reference Close relationship with arrays and strings 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 Introduction Pointer Variable Declarations and Initialization Pointer Operators Calling Functions by Reference Using const with Pointers Bubble Sort Using Pass-by-Reference Pointer Expressions and Pointer Arithmetic Relationship Between Pointers and Arrays Arrays of Pointers Case Study: Card Shuffling and Dealing Simulation Function Pointers Introduction to Character and String Processing Fundamentals of Characters and Strings String Manipulation Functions of the String- Handling Library Introduction Pointers Powerful, but difficult to master Simulate pass-by-reference Close relationship with arrays and strings 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 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 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 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 (1 of 2) 1 // Fig. : 2 // Using the & and

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.