W orking w ith Strings &
Standard Functions
CHAPTER OUTLINE
8.1
Introduction
8.2
Declaration and Initialization of String
8.3
Display of Strings with Different Formats
8.4 String Standard Functions
8.5 Applications of Strings
Exercises
8.1 INTRODUCTION
In C language the group of characters, digits, and symbols enclosed within quotation marks are
called as string. The string is always declared as character arrays. In other words character arrays
are called Strings. To manipulate text such as words and sentences normally strings are used. Every
string is terminated with 1 \
0' (NULL) character. The NULL character is a byte with all bits at logic
zero. Hence, its decimal value is zero.
For Example
char name[ ] = { 1I //fN///D/#/I #//A/#/\0/};
Each character of the string occupies 1 byte of memory. The last character is always ' \0'. It is not
compulsory to write 1 \0' in string. The Compiler automatically puts 1 \0' at the end of the character
array or string. The characters of string are stored in contiguous (neighboring) memory locations.
Table 8.1 given below shows uh e storing of string elements in contiguous memory locations.
Table 8.1 Memory map of string.
I N D I A
\0
5001 5002 5003 5004
5005 5006
8.2 DECLARATION AND INITIALIZATION OF STRING
The above string can also be initialized as follows,
char name[ ]= " INDIA";
The C compiler inserts the NULL (\0) character automatically at the end of the string. So
initialization of NULL character is not essential.
Also,

Get Programming and Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.