DSA Array&Strings Lecture 5
DSA Array&Strings Lecture 5
Arrays
An array is a collection of data elements of similar type, such that the
elements in the array are stored at contiguous memory locations
Arrays have indexes, which can be used to access elements. Generally, in most
programming languages, indexing starts from 0, which means that the index of
the first element is 0
Consider, the following code block, which contains an array, and the indexes of
the different elements in the array
Strings
Strings are a group of characters. They can also be referred as an array of
characters
The difference between a string and an array of characters, lies in the way
they are stored in the memory
Strings are stored in memory such that, they terminate with a special
character, \0
Just like in arrays, strings also have indexes, which can be used to fetch
character. For example, consider the string → aabcc , the element stored at
$0th$ position is a , while the character stored at the second position is
also a , the element stored at 3rd position is b , and so on
Some general terms associated with strings are → Substrings and Subsequences
A substring is a continuous sequence of characters within a string.