Learn C Programming

Lesson 3 of 9 · Dynamic Memory

Module 14 · Dynamic Memory

Growing an Array While the Program Runs

Free with an accountReading

Zara's weather sensor sends readings until its battery dies, and nobody knows when that will be. Her program must keep every reading, so the array has to grow while it reads.

Sign in to read

This lesson is free, with an account

An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.

What is inside Growing an Array While the Program Runs

  1. A fixed capacity is a guess
  2. Count and capacity live together in a struct
  3. push: grow when full, then store
  4. Zara times three growth rules
  5. Reading to the end of input
  6. A string builder grows the same way
  7. Shrink to fit, once, at the end