› Module 8: Strings › 8.2 Standard String-Handling Functions
M O D U L E

Module 8: Strings

How C represents text as arrays of characters, and the standard functions used to manipulate them.

8.1 String Basics and the Null Terminator

C has no dedicated string type — a string is simply a char array ending with the special null character '', which marks where the text stops. "Hello" therefore actually occupies 6 bytes (5 letters + the terminator), not 5. Every string-handling function relies on finding this to know where to stop reading or writing.

char str[6] = "Hello";
H [0] e [1] l [2] l [3] o [4] � [5]

C strings are char arrays terminated by a NULL character ().
Functions like strlen() scan until they hit to find the length.

A 6-byte char array storing the 5-letter string "Hello".

Two-Pointer Palindrome Verification in C

Because a C string is a null-terminated character array, we can verify whether it is a palindrome using two pointers moving inward, achieving O(n) time and O(1) space:

int isPalindrome(char *s) {
  int i = 0, j = strlen(s) - 1;
  while (i < j) {
    if (s[i] != s[j]) return 0; // false
    i++;
    j--;
  }
  return 1; // true
}
i ↓ j ↓ m a d a m i and j move inward, comparing character by character
Figure 8.2 — Checking a palindrome in C with two moving pointers.

8.2 Standard String-Handling Functions

The library provides the core toolkit for text manipulation. These functions all scan up to the null terminator internally, so passing a char array without one causes undefined (often crashing) behaviour.

Function Purpose
strlen(s)Returns the length of s, not counting
strcpy(dst,src)Copies src into dst, including
strcat(dst,src)Appends src onto the end of dst
strcmp(a,b)Returns 0 if equal; <0 or >0 otherwise
strchr(s,c)Finds first occurrence of character c in s
MODULE COMPREHENSIVE QUIZ

Module 8 Final Quiz

Test your understanding across all 2 topics of this module with interview-grade questions, tricky edge cases, and code output predictions.

Take Module 8 Final Quiz →
Yukti Mascot