Article by: Manish Methani
Last Updated: November 2, 2021 at 2:04pm IST
Strings are a fundamental data type in C programming used to store and manipulate text. In this tutorial, you will learn about the basics of strings in C programming with codes and examples.
To declare a string in C programming, you need to define a char array with a size that is large enough to store the string plus one for the null terminator character. For example:
char str[10];
In this example, the size of the char array is 10, which means it can store a string of up to 9 characters plus one for the null terminator.
There are two ways to initialize a string in C programming. You can either initialize it at the time of declaration or assign a value to it later. For example:
char str1[] = "Hello"; char str2[6]; str2[0] = 'W'; str2[1] = 'o'; str2[2] = 'r'; str2[3] = 'l'; str2[4] = 'd'; str2[5] = '