A collection of characters in a linear sequence can be called a string. It is treated as a single data by C even if it contains white spaces. A single character in a string is generally defined using single quotation representation. While the entire string is represented using double quotation marks.
For example, “Hey! There I am Rajshree Verma”
To perform complicated operations easily on Strings in C standard library <string.h> is provided by C that contains many functions.
Declaring a c strings:-
A C String can also be treated as a simple array with char as a data type. String is not generally supported by C language as a data type directly. Therefore , to display a c strings, we will need to make use of a character array.
Syntax for declaring a variable as a String in C can be found bellow,
Another way of declaring string which is common:-
char stringzVarName[stringLength] = “ourString”;
We have to define the size of an array while declaring a c strings variable because it will be used in calculating the number of characters that are going to be stored inside the string variable in C. Some of the examples of string declaration can be found bellow,
The above example here are representing string variables with an array size of 12. This shows that the given C string array can hold up to 15 characters at most. The indexing of array generally begins from 0 hence characters will be stored from a 0-11 position. A NULL character ‘\0’ is automatically added by the C compiler to the character array created.
Initializing a c strings:-
Following example is showing the initialization of c strings,