Skip to content
Guest
Learn C · Course Syllabus Show lessons
Memory & Data · 9 min read · Intermediate

Arrays & Null-Terminated Strings

Work with contiguous fixed-size arrays, compute array lengths with sizeof, and handle C strings ending in '\0'.

What you'll learn

  • Declare and iterate over fixed-size contiguous arrays
  • Understand why C strings end with the null terminator '\0'
  • Avoid buffer overflows by passing explicit lengths and using snprintf

An array in C is a contiguous block of elements in memory with zero hidden metadata: C does not store the array’s length next to it, and it does not perform automatic bounds checking.

C Strings Are char Arrays Ending in '\0'

The literal "Hi" occupies 3 bytes: 'H', 'i', and '\0' (the null byte). Functions like strlen() scan forward until they hit '\0'.

Fill-in-the-Blank Exercise

Compute Array Element Count

Compute the number of elements in a local fixed array using sizeof.

int scores[] = {80, 90, 100};
size_t count = (scores) / sizeof(scores[]);

Interactive Code Lab

Carrays_strings.c
Expected OutputClick “Run Live” to compile with GCC 13 (C11)
Name: DevPath (len=7)
Average: 90.0

Check Your Understanding

Score: 0 / 1

1. How many bytes does the C string literal "Cat" occupy in memory?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind