← All lectures

Lecture 22 · 35 min

Strings — Character Arrays

Storing text as null-terminated character arrays — declaration, initialization, input with cin / getline, and 2D arrays of strings.

char arraysNull terminator \0cin vs getline2D string arraysString operations
Slide 1 / 16

What is a string?

A string is a sequence of characters. In daily life: words, sentences, names, messages.

In C++, a string literal (text between double quotes) is a sequence of characters automatically terminated with a null character \0.

Examples of string literals:

  • "Hello" — 5 characters + \0
  • "CS501" — 5 characters + \0
  • "" — empty string, just \0
← / → navigateF fullscreenEsc exit⌘K search