Skip to main content
Logo image

Chapter 17 Arrays

With our current knowledge, if we wish to store someone’s name in the computer’s memory we’d have to create a variable for each character in the name in order to do so. For example, to store all of the letters in “Petra” we’d need five variables of type char to store the individual letters, such as char letter1 = 'P', char letter2 = 'e', ... , char letter5 = 'a'. This is not exactly convenient and there is a better way to do so, using a so-called array. An array is a collection of items of the same datatype that you can access via one variable name. We’ll start by learning about one-dimensional arrays which can also be thought of as lists. In this chapter, we’ll focus on such one-dimensional arrays and practice working with them. Specifically, we’ll learn about: