ConceptStep · learning platform for computer science

Strings: char arrays and the \0 terminator

C programming · Lesson

C · lesson 21 / 27

Strings: char arrays and the \0 terminator

Observe a C string as a sequence of characters in memory and discover why one extra cell is needed for the terminator.

1 · Observe and predict

The concept

In C, a string is a char array terminated by byte 0. The \0 terminator lets functions such as printf with %s know where to stop.

Mental model:

"CIAO" → ['C','I','A','O','\0'] → %s reads until \0

2 · Flowchart + String Memory

Follow the same algorithm as a flowchart

The flowchart shows the logical string value; the String Memory Explorer below shows the individual char cells and the \0 terminator actually required in C.

Loading flowchart…
3 · String Memory Explorer

See the string as memory cells

Each cell contains one char. The \0 terminator occupies a real cell and tells C functions where the string ends.

1 / 4

The literal becomes a char array

"CIAO" has four visible characters, but five memory cells are required.

4 · Flowchart ↔ C · Run in Page

Lab 1 — Run the example program

Run C executes only the example shown on the left, using stdin on the right. The coding challenge below has a separate editor and test button.

Strings: char arrays and terminator Start the flowchart to synchronize the code
                        1#include <stdio.h>
                        2 
                        3int main(void)
                        4{
                        5    char parola[] = "CIAO";
                        6    printf("%s\n", parola);
                        7    return 0;
                        8}
Ready. Make a prediction before running.

                    
                

Lab 2 — Coding challenge: write your code — String terminator

Read a word (max 50 chars); print bytes needed including null terminator.

This is a different program from lab 1. Complete the starter code: Check all test cases compiles this editor and tests every input, including boundary cases.

5 · Guided practice

Check your prediction

How many cells does char parola[] = "CIAO" occupy?

Challenge 1 / 5 · Understanding

Progress: 0 / 5 · correct: 0

Your competency map

What you need to know for Strings: char arrays and the \0 terminator

ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.

Current topic Strong skill Review due Needs reinforcement To be mastered Optional support

Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.

GUIDED LEARNING PATHS

Want to choose the next skill to develop?