Nearby lessons

39 of 72

C - Arrays

Learn what an array is in C, understand its syntax, and learn the names of different types of arrays.

What Is an Array?

An array is a collection of multiple values of the same data type stored under one variable name. For example, instead of creating five separate variables to store five marks, we can use one array. Each value in an array has an index. In C, the index starts from 0.
Example01
CCode Cell
1 
2#include <stdio.h>
3 
4int main() {
5 int marks[5] = {70, 80, 65, 90, 85};
6 
7 printf("%d\n", marks[0]);
8 printf("%d\n", marks[1]);
9 
10 return 0;
11}
12
Output

70
80
      

Array Syntax

The basic syntax of an array is: data_type array_name[size]; - data_type: The type of values stored in the array. - array_name: The name given to the array. - size: The number of elements the array can store. Example: int numbers[5]; This creates an integer array that can store five elements.
Example02
CCode Cell
1 
2int numbers[5];
3float prices[10];
4char letters[4];
5

Types of Arrays

The main types of arrays in C are:

1. One-Dimensional Array
2. Multidimensional Array
We will learn each type in the upcoming lessons.
📝 Key Takeaways
  • An array stores multiple values of the same data type.
  • Array indexing starts from 0.
  • C supports one-dimensional, two-dimensional, and multidimensional arrays.