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.

Checking what this lesson needs for you…

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