Synopses & Reviews
Improve your programming through a solid understanding of C pointers and memory management. With this practical book, youll learn how pointers provide the mechanism to dynamically manipulate memory, enhance support for data structures, and enable access to hardware. Author Richard Reese shows you how to use pointers with arrays, strings, structures, and functions, using memory models throughout the book.
Difficult to master, pointers provide C with much flexibility and power—yet few resources are dedicated to this data type. This comprehensive book has the information you need, whether youre a beginner or an experienced C or C++ programmer or developer.
- Get an introduction to pointers, including the declaration of different pointer types
- Learn about dynamic memory allocation, de-allocation, and alternative memory management techniques
- Use techniques for passing or returning data to and from functions
- Understand the fundamental aspects of arrays as they relate to pointers
- Explore the basics of strings and how pointers are used to support them
- Examine why pointers can be the source of security problems, such as buffer overflow
- Learn several pointer techniques, such as the use of opaque pointers, bounded pointers and, the restrict keyword
Pointers are more involved than most programmers think and are frequently poorly understood. Comprehending and Using C Pointers will provide beginning and advanced C programmers with a comprehensive coverage of C pointers and illustrate good pointer programming habits, demonstrate the variety of ways they can be used. Comprehending and Using C Pointers will address an area that has been neglected and provide the deep understanding of pointers necessary to create a properly functioning application.
Although C is extensively use in industry applications, many aspects of pointers are not covered adequately in a typical C book. This book will use graphical models and comprehensive examples to illustrate key concepts and fundamentals of pointers, address compiler specific pointer techniques, and convey the dynamics of pointers and programming in general.
About the Author
Richard Reese has worked in the industry and academics for the past 29 years. For 10 years he provided software development support at Lockheed and at one point developed a C based network application. He was a contract instructor providing software training to industry for 5 years. Richard is currently an Associate Professor at Tarleton State University in Stephenville Texas.
Table of Contents
Preface; Why This Book Is Different; The Approach; Audience; Organization; Summary; Conventions Used in This Book; Using Code Examples; Safari® Books Online; How to Contact Us; Chapter 1: Introduction; 1.1 Pointers and Memory; 1.2 Pointer Size and Types; 1.3 Pointer Operators; 1.4 Common Uses of Pointers; 1.5 Summary; Chapter 2: Dynamic Memory Management in C; 2.1 Dynamic Memory Allocation; 2.2 Dynamic Memory Allocation Functions; 2.3 Deallocating Memory Using the free Function; 2.4 Dangling Pointers; 2.5 Dynamic Memory Allocation Technologies; 2.6 Summary; Chapter 3: Pointers and Functions; 3.1 Program Stack and Heap; 3.2 Passing and Returning by Pointer; 3.3 Function Pointers; 3.4 Summary; Chapter 4: Pointers and Arrays; 4.1 Quick Review of Arrays; 4.2 Pointer Notation and Arrays; 4.3 Using malloc to Create a One-Dimensional Array; 4.4 Using the realloc Function to Resize an Array; 4.5 Passing a One-Dimensional Array; 4.6 Using a One-Dimensional Array of Pointers; 4.7 Pointers and Multidimensional Arrays; 4.8 Passing a Multidimensional Array; 4.9 Dynamically Allocating a Two-Dimensional Array; 4.10 Jagged Arrays and Pointers; 4.11 Summary; Chapter 5: Pointers and Strings; 5.1 String Fundamentals; 5.2 Standard String Operations; 5.3 Passing Strings; 5.4 Returning Strings; 5.5 Function Pointers and Strings; 5.6 Summary; Chapter 6: Pointers and Structures; 6.1 Introduction; 6.2 Structure Deallocation Issues; 6.3 Avoiding malloc/free Overhead; 6.4 Using Pointers to Support Data Structures; Chapter 7: Security Issues and the Improper Use of Pointers; 7.1 Pointer Declaration and Initialization; 7.2 Pointer Usage Issues; 7.3 Memory Deallocation Issues; 7.4 Using Static Analysis Tools; 7.5 Summary; Chapter 8: Odds and Ends; 8.1 Casting Pointers; 8.2 Aliasing, Strict Aliasing, and the restrict Keyword; 8.3 Threads and Pointers; 8.4 Object-Oriented Techniques; 8.5 Summary; Colophon;