Character arrays and strings

A string is an array of characters. A group of characters (except double quote sign) defined between double quote marks is string.

printf (“welcome to C”) /* this is a character string. *

In C characters strings are widely used to build more readable program in a more meaningful way. The common operations that are performed on character strings are as follows:

  • a) Reading and writing strings
  • b) Combining strings together
  • c) Copying one strings for another
  • d) Comparing strings for equality
  • e) Extracting a portion of a string

Declaration of strings variable

In C, a strings is defined as a character array that is terminated by a null (‘\0’) character. it uses character array to store strings. There is no string data type. The general form of declarations is

char string – name [size];

The size determines the number of characters in the string – name. some examples are:

char ename [30];
char city [15]

The size of the string must be equal to the maximum number ox characters plus in since the last character should store ‘\0’ value. For example, if we are declaring an array which will hold 10 characters string. The declaration must be:

Char name [11];

C also permit to declare a character array without specifying the number of elements. For example, the declaration statement,

char name [] ={‘t’,’u’,’i’,’s’,’i’,’\o’};

is an array string with sis elements. The above example will also indicate how an array must be initialised. Many character array are initialised as and when they are declared. For example, the two forms of initiasation are:

char name [6] = “Tulsi”;
char name [6] = {‘T’,’U’,’L’,’S’,’I’,’\0’};

C provides no explicit support for strings in the language itself, all of the string – handling functions are implemented in libraries. The strings I/O operations (gets, puts, and so on) are implemented in <stdio.h>, and a set of fairly simple string manipulation functions are implemented in <string.h> (on some systems,<strings.h>).



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext