2-dimentional array
Advantages
2-dimentional array
Advantages
- Easy visualization of parallel data
- Simple row-column access pattern
- Efficient for matrix analysis
- Natural representation for grids and tables
Disadvantages
- It is sparse and cannot load dynamically
- Memory waste of array is fast
- Complexity increases with time
Real-Life Examples
Some real-life examples are:
- Chessboard
- Paper seating arrangement
- Excel table
- Classroom seating chart
How to Declare an Array
The syntax is: data type, array name, rows, and columns.
Initialization
There are two results: one is at the time of declaration and the other is after declaration.
At the Time of Declaration
Each inline curly brace represents one row. Elements are assigned row by row, and then all elements are initialized at once.
After Declaration
Elements are assigned individually, using row and column, and they can initialize selected elements only.
Traversing in 2D Arrays
There are types of traversing. Traversing in 2D arrays includes:
- Row-wise traversing
- Column-wise traversing
- Diagonal traversing
- Spiral traversing
This code prints a 2D array row by row. The outer loop goes through each row. The inner loop prints all elements in that row with spaces, and then it moves to the next line after each row is completed.
Data Flow Diagram
The first one is declaring the array using the data type, and then initializing the assigned values. Then we access the elements using array, row, and column. Then we create the value, or we can either move by the value, and then finally process the data.
Summary and Key Takeaways
Now we have come to the end of the presentation, and we will summarize. The key takeaways are:
- 2D arrays can organize data in rows and columns.
- Declaration: data type, array name, rows, and columns.
- There are two initialization methods available.
- Arrays are stored in row-major order in memory.
- These are essential for matrix and cardinal data handling.
메타데이터
- post_id
- 2aec65bc9ca6
- slug
- 2-dimentional-array-2aec65bc9ca6
- url
- https://medium.com/@shruthika.sharon/2-dimentional-array-2aec65bc9ca6
- canonical_url
- https://medium.com/@shruthika.sharon/2-dimentional-array-2aec65bc9ca6
- author_url
- https://medium.com/@shruthika.sharon
- status
- ok
- fetched_at
- 2026-06-23 03:48:11