Back to Course
Arrays & Strings

Strings in C with Examples: String Functions

What is a String in C?

A string in C is an array of characters terminated by a null character '\0'.

Declaring Strings

char name[20] = "Hello";
char name2[] = {'H','i','\0'};

Common String Functions (string.h)

  • strlen(str) — returns the length of a string.
  • strcpy(dest, src) — copies one string into another.
  • strcat(dest, src) — appends one string to another.
  • strcmp(str1, str2) — compares two strings, returns 0 if equal.
  • strrev(str) — reverses a string (non-standard, compiler-dependent).
char a[20] = "Hello";
printf("%d", strlen(a));  // 5

Ready to master real-world C Programming development?

Learn C Programming hands-on with mentor-led, live sessions.

Explore Course