Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

strings-c

Strings in C

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Strings in C: the syntax, patterns, and safety habits you need before advancing in C.

Teams still ship Strings in C in C codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Strings in C in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

C has no built-in string type. Text is a null-terminated array of char ending with '\0'. Use <string.h> for common operations.

Literals and buffers

const char *msg = "hello";   /* read-only literal */
char buf[32] = "copy me";    /* mutable buffer */

Never write through a string literal pointer—storage is read-only.

Common functions

  • strlen(s) — length excluding null terminator
  • strcpy(dst, src) — copy (ensure dst is large enough)
  • strcmp(a, b) — compare; returns 0 if equal

Prefer strncpy, snprintf, or bounded copies in production code.

Important interview questions and answers

  1. Q: Why crash on strcpy without space?
    A: Buffer overflow—writes past the destination array into adjacent memory.
  2. Q: char* vs char[]?
    A: Pointer may aim at a literal (often read-only); array is mutable storage on stack or static memory.

Self-check

  1. What character terminates a C string?
  2. Which function measures string length?

Pitfall: strcpy without bounds checking causes buffer overflows—prefer snprintf or bounded copies in production code.

Interview prep

How are C strings stored?

Contiguous char arrays ending with a null terminator \0.

strcpy danger?

Writes until source null byte with no destination size check—classic buffer overflow source.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • char* vs char[]?
  • strlen cost?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump