Chapter 7


The variables we’ve used so far can store a single value. In this chapter, we’ll talk about a new type of variable capable of storing a number of values. This type is called array. An array may be multidimensional. We’ll focus on the simplest and most usual kinds; the one-dimensional and two-dimensional arrays. To introduce you to arrays, we’ll show you how to use arrays of integers and floating-point numbers. We’ll discuss other types of arrays, as well as their close relationship to pointers in later chapters.

Declaring Arrays

An array is a data structure that contains elements of the same data type. To declare a one-dimensional array, you must specify its name, the number of its elements, and their data type, like this:

Get C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.