Strings:


A string is a sequence of characters terminated by a null character ‘\0’. The null character indicates the end of the string. Each character that composes a string is stored in an one-dimensional char type array in contiguous memory locations. For example: The string “ Try Again “ is a collection of characters ‘T’, ‘R’, ‘Y’, ‘ ‘, ‘A’, ‘G’, ‘A’, ‘I’, ‘N’ and terminated by ‘\0’ (null character). The termination character (‘\0’) is automatically inserted at the end of the sting by the compiler. As strings is a one-dimensional array of characters so the characters in the string “ TRY AGAIN” will be stored in contiguous memory locations as shown below:


In C, as each character requires 1 byte for its storage so the total memory used for storing the string “ Try Again “ will be 10 (= 3 + 1 + 5 + 1) bytes.
The strings are enclosed in double quotes (““) and may include letters, numbers, escape sequences, blank space and some special characters. Some valid strings are
                        “Good Morning”
                        “Welcome to the world of Programming”
                        “A”
                        “1111111”
The common operations performed on character strings include:
i.                    Reading and writing strings.
ii.                  Combining strings together
iii.                Copying one string to another.
iv.                Comparing two strings for equality.

v.                  Extracting a portion of a string.

Previous                                                                                    Next


Powered by Blogger.