C Pointer

Table of Contents

1. Pointer in C - Storage allocation   c

When we declare a variable, its type tells the compiler how much storage to set for it. Storage for the variable is allocated automatically.

  • Never assume a pointer has a specific size.
  • Space is allocated only for the pointer itself, not for the referece data.

Storage for the data is allocated in two ways:

  • declaring a variable
  • by allocating stroage dynamically at runtime (using malloc, realloc)

2. Arrays in C with Pointer   c

Array Reference:

int f() {
  int a[10], *iptr;
  iptr = a;
  iptr[0] = 5;

  return 0;
}

Pointer Reference:

int f(){
  int a[10], *iptr;
  iptr = a;
  *iptr = 5;

  return 0;
}

Date: 2024-11-24 Sun 00:00

Author: Terry Fung

Created: 2025-03-02 Sun 22:47

Emacs 29.4 (Org mode 9.6.15)

Validate