Introduction to Arrays
Whereas numbers and characters are scalar variables—meaning they contain only a single value at a time—arrays are a more complex structure. An array allows you to store a series of values, all under the heading of one variable. It's perhaps easiest to think of arrays as a two-column table (Table 6.1).
A Simple Array | |
---|---|
Key | Value |
0 | 98.5 |
1 | 74.3 |
2 | 82.0 |
Arrays consist of key-value pairs, each pair constituting an element. By referencing a specific key (also called its index), you can obtain that corresponding value.
You create an array much like any other variable: by giving it a type and a name. The type will apply to every element in ...
Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.