Arrays and Strings

Arrays are a fundamental data structure, and they are extremely useful. We use arrays to hold values of the same type at contiguous memory locations. In particular, the use of arrays allows us to create “groups” or “clusters” of variables without needing to give a unique variable name to each, but still allowing us to individually index into the elements of the array. If you haven’t started counting from zero yet, now is the time, because in C, arrays are zero-indexed which means the first element of a k-element array is located at array index 0 and the last element is located at array index k-1.

Strings are a special case of arrays – in C, a string is an array of characters (more modern programming languages have strings as their own data type related to but distinct from characters). Later in the course, we’ll examine this special case a bit further, but for now, it suffices to group and discuss arrays and strings together. In this section, you will learn how to create and manipulate arrays.