ter 15: Strings
oe ee
nthe last chapter, we learnt how to define arrays of various sizes and
dimensions, how to initialize arrays, how to pass arrays to a aca
etc. With this knowledge under our belt, we should be ready to ale
strings, which are, simply put, a special kind of array. And strings, the
ways to manipulate them, and how pointers are related to strings are
going to be the topics of discussion in this chapter.
The way a group of integers can be stored in an integer array, similarly a
group of characters can be stored in a character array. They are used to
manipulate text, such as words and sentences.
A string is a 1-D array of characters terminated by a null ( ‘\O' }. For
example,
char name[]={'H',
‘\0' is called null character. Note that '\0’ and
value of ‘\0' is 0, whereas ASCII value of 0’ is 48. Figure 15.1 shows the
way a string is stored in memory. Note that the elements of the string
are stored in contiguous memory locations.
((\o’) is important, because it is the only way the
g can know where the string ends. In
"\0" is not really a string, but merely @
The terminating null
functions that work with a strin
fact, a string not terminated by a
collection of characters.
Figure 15.1
often and hence
the string used
would use strings Very
For example,
C concedes the fact that you :
Provides a shortcut for initializing strinés-
above can also be initialized 25,
the null
Note that, in this dectaration "Wo" s not necessary Core
ct
haracter automatically.