Strings in C
Discover how strings are implemented in C using character arrays and how to manipulate them using built-in functions like strlen, strcpy, strcat, and strcmp.
Strings in C is a free C Academy lesson on CoddyKit. This is lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.
What Is a String in C?
Strings in C
In C, strings are sequences of characters stored in character arrays and terminated by a null character \0.
In this lesson, you will learn:
- How to declare and initialize strings.
- How to manipulate strings using standard functions.
- The difference between character arrays and string literals.

Declaring a String
A string in C is declared as a character array.
Example:
char name[10];
This creates an array that can store a string of up to 9 characters plus the null terminator \0.
Initializing a String
Strings can be initialized in two ways:
- Using a character array:
- Using a string literal:
char name[] = {'J', 'o', 'h', 'n', '\0'};
char name[] = "John";
Printing a String
The printf function is used to print a string:
printf("%s", name);
Example:
char name[] = "Alice";
printf("Hello, %s!", name);Example: Printing a String
This program demonstrates how to store and print a string.
#include <stdio.h>
int main() {
char name[] = "Alice";
printf("Hello, %s!\n", name);
return 0;
}String Input Using scanf()
To read a string input from the user, use scanf:
char name[20];
scanf("%s", name);
Warning: scanf does not read spaces in strings.
Example: Taking String Input
This program demonstrates how to take a string input using scanf.
#include <stdio.h>
int main() {
char name[20];
printf("Enter your name: ");
scanf("%s", name);
printf("Hello, %s!\n", name);
return 0;
}Common String Functions
C provides several string manipulation functions:
strlen(str)- Returns string length.strcpy(dest, src)- Copies one string to another.strcat(dest, src)- Concatenates two strings.strcmp(str1, str2)- Compares two strings.
String Basics Recap
Summary
In this lesson, you learned:
- How to declare and initialize strings.
- How to print and take string input.
- How to use basic string functions.
Next, we will explore pointers and memory management in C!

Learn C with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 39
- Lessons
- 144
Frequently Asked Questions
Is the “Strings in C” lesson free?
Yes — the full text of “Strings in C” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 3 lessons in total.
What will I learn in “Strings in C”?
Discover how strings are implemented in C using character arrays and how to manipulate them using built-in functions like strlen, strcpy, strcat, and strcmp. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.
How long does the “Strings in C” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Arrays
- Multidimensional Arrays
- Strings in C