Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Two Dimensional Arrays | Data
C Basics

bookTwo Dimensional Arrays

Two-dimensional arrays are a bit like tables, think of them as arrays within arrays, with rows and columns. Declaring a two-dimensional array requires an extra set of square brackets:

int array[ROWS][COLUMNS];

Imagine a table where:

  • Row a[0]... represents the first set of data or the first array;
  • Row a[1]... is the second set;
  • Row a[2]... is the third.

When an array is placed inside another array, it's called a nested array. To access its elements, use multiple indices, each enclosed in its own set of brackets.

main.c

main.c

copy
123456789101112131415
#include <stdio.h> int main() { // dimensional array declaration int array[3][4] = { {1, 11, 111, 1111}, // Index `[0]` {2, 22, 222, 2222}, // Index `[1]` {3, 33, 333, 3333} // Index `[2]` }; // Print the first element of the second nested array printf("%d", array[1][0]); return 0; }
Note
Note

All elements within an array must be of the same type.

question mark

What is the output of this code?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 5

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

Can you explain how to access a specific element in a two-dimensional array?

What are some common use cases for two-dimensional arrays?

Can you show how to initialize a two-dimensional array with values?

Awesome!

Completion rate improved to 2.63

bookTwo Dimensional Arrays

Scorri per mostrare il menu

Two-dimensional arrays are a bit like tables, think of them as arrays within arrays, with rows and columns. Declaring a two-dimensional array requires an extra set of square brackets:

int array[ROWS][COLUMNS];

Imagine a table where:

  • Row a[0]... represents the first set of data or the first array;
  • Row a[1]... is the second set;
  • Row a[2]... is the third.

When an array is placed inside another array, it's called a nested array. To access its elements, use multiple indices, each enclosed in its own set of brackets.

main.c

main.c

copy
123456789101112131415
#include <stdio.h> int main() { // dimensional array declaration int array[3][4] = { {1, 11, 111, 1111}, // Index `[0]` {2, 22, 222, 2222}, // Index `[1]` {3, 33, 333, 3333} // Index `[2]` }; // Print the first element of the second nested array printf("%d", array[1][0]); return 0; }
Note
Note

All elements within an array must be of the same type.

question mark

What is the output of this code?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 5
some-alt