Pointers in C: A Hands on Approach

Book description

Pointers in C provides a resource for professionals and advanced students needing in-depth but hands-on coverage of pointer basics and advanced features. The goal is to help programmers in wielding the full potential of pointers.

In spite of its vast usage, understanding and proper usage of pointers remains a significant problem. This book's aim is to first introduce the basic building blocks such as elaborate details about memory, the compilation process (parsing/preprocessing/assembler/object code generation), the runtime memory organization of an executable and virtual memory. These basic building blocks will help both beginners and advanced readers to grasp the notion of pointers very easily and clearly. The book is enriched with several illustrations, pictorial examples, and code from different contexts (Device driver code snippets, algorithm, and data structures code where pointers are used).

Pointers in C contains several quick tips which will be useful for programmers for not just learning the pointer concept but also while using other features of the C language. Chapters in the book are intuitive, and there is a strict logical flow among them and each chapter forms a basis for the next chapter. This book contains every small aspect of pointer features in the C language in their entirety.

What you'll learn

  • The concept of pointers and their use with different data types

  • Basic and advanced features of pointers

  • Concepts of compilers, virtual memory, data structures, algorithms and string processing

  • Concepts of memory and runtime organization

  • Referencing and dereferencing of pointer variables

  • NULL pointers, Dangling pointers, VOID pointers and CONST qualifiers

  • Workings of dynamic data structures

  • Pointers to pointers

  • Triple, and quadrupal pointers

  • Self referential structures, structure padding, and cache based optimization techniques.

  • Who this book is for

    Professional programmers, advanced students of computer science, and enthusiasts of the C language. Embedded systems programmers will also find the advanced knowledge of pointers offered in this book very helpful.

    Table of contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Authors
    6. Acknowledgments
    7. Introduction
    8. CHAPTER 1: Memory, Runtime Memory Organization, and Virtual Memory
      1. Memory and Classification
      2. Data and Instruction
      3. Compilation Process Chain
      4. Memory Models
      5. Memory Layout Using Segments
      6. Runtime Memory Organization
      7. Memory Segments
      8. Virtual Memory Organization
      9. Summary
    9. CHAPTER 2: Pointer Basics
      1. What is an address of a variable?
      2. Address of Operator
      3. Pointer Declaration
      4. Pointer Assignment
      5. Size of Pointer Variables
      6. Pointer Dereferencing
      7. Basic Usage of Pointer
      8. Pointers and Constants
      9. Multilevel Pointers
      10. Understanding a Cryptic Pointer Expression
      11. Summary
    10. CHAPTER 3: Pointer Arithmetic and Single Dimension Arrays
      1. Array Memory Layout
      2. Pointer Arithmetic
      3. Arrays Explored
      4. Summary
    11. CHAPTER 4: Pointers and Strings
      1. String Layout in Memory
      2. Dynamic Memory Allocation
      3. String Operations
      4. Array of Strings
      5. Summary
    12. CHAPTER 5: Pointers and Multidimensional Arrays
      1. Array Layout
      2. Summary
    13. CHAPTER 6: Pointers to Structures
      1. Defining Structures
      2. Declaring Structure Variables
      3. Accessing Structure Members
      4. Initializing Structure Variables
      5. Structure Nesting
      6. Structure in Memory
      7. Structure Padding
      8. When Structure Padding is not Helpful
      9. Structure Packing
      10. Structure Assignment and Copying
      11. Structure Pointers
      12. Common Mistakes
      13. Type Casting Structure Pointers
      14. Self-Referential Structures
      15. Data Structures and Algorithms
      16. Summary
    14. CHAPTER 7: Function Pointers
      1. Defining Function Pointers
      2. Initializing Function Pointers
      3. Using Function Pointers
      4. Assembly Details of Function Pointer Calls
      5. Array of Function Pointers
      6. Returning Function Pointers from Function
      7. Function Pointer Usage in the Linux Kernel
      8. Summary of Cryptic Function Pointer Declarations
      9. Summary
    15. CHAPTER 8: Pointers to File I/O
      1. The Physical Layout of Secondary Memory
      2. Introduction to File System Architecture
      3. What Is Required to Make a File System?
      4. Accessing Files
      5. First Task
      6. Second Task
      7. Reading from a File
      8. Writing to a File
      9. Accessing Disk at Random Locations
      10. Miscellaneous Functions
      11. Summary
    16. Index

    Product information

    • Title: Pointers in C: A Hands on Approach
    • Author(s): Naveen Toppo, Hrishikesh Dewan
    • Release date: December 2013
    • Publisher(s): Apress
    • ISBN: 9781430259114