Arrays

Lesson 15
Author : Afrixi
Last Updated : January, 2023
C - Programming Language
This course covers the basics of programming in C.

Arrays are a type of data structure in C that allow you to store multiple values of the same data type under a single variable name. Arrays can be thought of as a collection of elements of the same type, arranged in a contiguous block of memory.

To declare an array in C, you specify the data type of the elements and the number of elements in the array, like this:

int myArray[5];

This declares an array called myArray that can hold five integers. To access the individual elements of the array, you use the array name followed by an index inside square brackets. Array indices start at 0, so to access the first element of the array, you would use:

myArray[0];

You can also initialize an array when you declare it by providing a comma-separated list of values enclosed in curly braces:

int myArray[] = {1, 2, 3, 4, 5};

This creates an array called myArray with five elements, initialized with the values 1, 2, 3, 4, and 5.

Arrays can be used in a variety of programming tasks, such as storing and manipulating lists of values, implementing sorting algorithms, and representing images and sound data.