Numbers and Strings

Uncategorized

STRINGS

String is a collection of characters Or String is a sequence of characters Or String is an array of characters A string variable is the name of array declared to hold a string of specified size. The declared size of array should be one more than the maximum size of the string, as every string must be terminated by null (‘\0’) character.

Initialization of Strings

A string can be initialized in two ways which are given as

  • Compile Time Initialization:-It is also know as Static initialization.
  • Run Time Initialization:-It is also know as Dynamic initialization.

Compile Time Initialization

A string can be initialized at compile time in following ways-
str = ( ‘w’,’e’,’l’,’c’,’o’,’m’,’e’,’\’)
str = “welcome”  //Null charecter is supplied automatically by compiler

Memory Representation of Strings:

Strings can be represented in following two ways –

  • Array Based Representation
  • Linked List Based Representation

Array Based Representation:

Linked List Based Representation

Operations on Strings:

The following operations can be performed on strings:-

  • Length of string
  • Copying of a string into another string
  • Appending a string to another string
  • Comparing two strings
  • Reversing a string
  • Extracting a sub string from left
  • Extracting a sub string from right
  • Extracting a sub string from middle
  • Converting alphabets of string to upper case
  • Converting alphabets of string to lower case