course-c

Introduction

:::: {.columns}

::: {.column width=”40%”}

:::

::: {.column width=”60%”}

A pointer is a variable that stores an address

:::

::::

Pointer declaration

Pointer assignment and usage

Function arguments

Arrays

:::: {.columns}

::: {.column width=”40%”}

:::

::: {.column width=”60%”}

An array

:::

::::

Array initialization

Pointers vs Arrays

:::: {.columns}

::: {.column width=”60%”}

:::

::: {.column width=”40%”}

Pointers vs Arrays

:::

::::

Pointer operations

Strings

Multi-dimensional arrays

Wasted space with multi-dimensional array

:::: {.columns}

::: {.column width=”60%”}

:::

::: {.column width=”40%”}

Space wasted due to array dimensions of fixed lengths

:::

::::

Array of pointers instead of multi-dimensional array

:::: {.columns}

::: {.column width=”60%”}

:::

::: {.column width=”40%”}

Array of pointers to char

:::

::::

Pointers to multi-dimensional array

:::: {.columns}

::: {.column width=”40%”}

  int a[2][2] =
    { {1,2}, {3,4} };
  int *b[2], **c, *d;
  b[0] = a[0];
  b[1] = a[1];
  c = b;
  d = (int *)a;

:::

::: {.column width=”60%”}

Visualizing pointers to arrays{width=50%}

:::

::::

Main function

:::: {.columns}

::: {.column width=”60%”}

:::

::: {.column width=”40%”} Visualizing argv :::

::::

Command line arguments

Pointers to Functions

void pointer

Dynamic memory allocation

malloc

calloc

Memory allocation problems

Using memwatch

Exercise