Introduction to strings in C language

An array of characters that ends with the null character “0” is referred to as a string. The string ends with the null character, which is not included in the string’s length calculation.

Text data is frequently stored in and modified by strings in C. The maximum amount of characters that can be saved can be determined in the declaration when they are declared as character arrays.

Example of declaring string:

char str[20];

In C, strings can also be initialized using string literals, which are enclosed in double quotes.

Example:

char greeting[] = "Hello, world!";

Once a string is declared and initialized, its individual characters can be accessed and manipulated using indexing.

Example:

char str[] = "Hello";
printf("%c\n", str[0]);   // Output: H
str[0] = 'J';
printf("%s\n", str);      // Output: Jello

String manipulation functions such as strcpy, strcat, and strlen are also available in the C standard library to help manipulate and work with strings.