Learn C Programming

Lesson 2 of 9 · Strings

Module 10 · Strings

Strings: an Array That Ends in a Zero

Free with an accountReading

Bob is printing name tags for Maria's shop. He counts the letters in Maria, gets five, and makes five boxes: char name[5] = "Maria";. Beside it sits char city[6] = "Dhaka";. GCC 12 says nothing, even at -Wall -Wextra, and the Playground printed Maria's tag as [MariaDhaka]. This lesson finds the box Bob forgot, the one that holds no letter at all.

Checking what this lesson needs for you…

What is inside Strings: an Array That Ends in a Zero

  1. A string is a row of chars that ends at a zero
  2. A string literal brings its own zero
  3. Walking a string until the zero
  4. Length and capacity are two numbers
  5. When the zero is missing
  6. Copying a string box by box
  7. Comparing two strings box by box