Apr 14, 20232D Arrays in C Tutorial 1 - Creating a 2D ArrayStarting the guide on 2D Arrays in C!
William Huynh βΈ± 2 min read

2D Arrays in C πŸ₯³

Welcome to our guide on 2D Arrays in C!

Here you will learn how to use and understand seamlessly the very scary topic that is 2D arrays!

To break it down nice and easy, we will be covering 6 operations:

  • Creating a 2D Array πŸ”§
  • Initialising a 2D Array πŸ“š
  • Accessing elements in a 2D Array πŸ”
  • Editing elements in a 2D Array ✏️
  • Iterating through a 2D Array πŸ”

Creating a 2D Array πŸ”§

Preface 🐢

A 2D array is often referred to as an array of arrays, or a matrix! This is because it consist of rows and columns, and thus takes the shape of a matrix!

Array Example

Getting Started πŸŽ‰

To create a 2D array in C, you will need to declare it using the following syntax:

<datatype> <arrayname> [row_size][col_size];

Where:

  • <datatype> is the datatype of the array (i.e. int, char, bool, etc...)
  • <arrayname> is the name of the array (i.e. my_array)
  • row_size is the number of rows in the array
  • col_size is the number of columns in the array

For example, to create a 2D array of integers with 2 rows and 4 columns, you would use the following declaration:

int my_array[2][4];

Pretty easy right?

βœ… Now lets get started on Initialising an array 😎