© Slobodan Dmitrović 2021
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6643-4_9

9. Arrays

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 

What is an array? An array is one or more data objects of the same type positioned next to each other in memory. Once declared, the array size is fixed, we cannot add nor remove elements to and from the array. The array itself is also a type.

9.1 Declaration

An array is a sequence of (one or more) elements of a certain type. To declare an array, we use the following syntax:
type_name array_name[array_size];
To declare an array of five integers, we write:
int main(void)
{
      int myarr[5];
}

The number 5 in the square brackets [] says how many array elements there are. We declared an array of ...

Get Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language 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.