Introduction to strings


A string is a sequence of characters that are considered a single data item. We have used strings in several instances in the past. Any group of characters defined within a double quotation mark is a string constant. Example :

"This is an example text."

If we want to include a double quote in the string to be printed, then we may use it with a back slash as shown below :

printf("\" This is an example text. "\");
// "This is an example text."

printf("This is an example text.");
// This is an example text.

Character strings are often used to create meaningful and readable programs. Common activities performed on character strings include:

  1. Reading and writing strings.
  2. Combining strings together.
  3. Copying one string to another.
  4. Comparing strings for equality.
  5. Extracting a portion of a string.