Skip to content

Strings in C

Strings in C Notes

A string in c is a character array, weakly typed, easy for any c programmer to screw up.

A string is ended by a null character \n.

char a[3] = {'c', 'a', 't'};

The above character array is not a string.

char b[4] = { 'c', 'a', 't', '\0'};

Array b[] contains four characters: c-a-t plus the null character. This terminating null character makes the array a string. It can be processed by any C language string function or output as a string.

To save time, a string can be created like this :

char c[4] = "cat";

Calculating the size of the string.

strlen()

C String Functions.