Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
    • Angular
    • C
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
  • Register
  • Login
  1. Home
  2. Blogpost

2-D Array in C

Date- Sep 25,2023

3792

A two-dimensional (2D) array is an arrangement of items in C that are arranged in a grid and are individually identified by a pair of indices: a row index and a column index. A 2D array can be compared to a table or matrix that has rows and columns. A 2D array in C is declared, initialised, and used as follows:

Declaration:

data_type array_name[row_size][column_size];


  • 1. data_type: The data type of the elements in the array (e.g., int, double, char, etc.).
  • 2. array_name: The name of the array.
  • 3. row_size: The number of rows in the array.
  • 4. column_size: The number of columns in the array.

Initialization: You can initialize a 2D array when declaring it, or you can assign values to individual elements later in your code.

Here's an example of declaring and initializing a 2D integer array:

int a[2][2];

Accessing Elements: You can access individual elements of a 2D array using the row and column indices. The indices are zero-based, meaning the first row and first column have index 0.

Example: Here's a complete example of declaring, initializing, and accessing elements in a 2D array:


In this example, we declare and initialize a 2x2 integer array called matrix and then access individual elements using their indices.

Remember that when working with 2D arrays in C, you need to be mindful of array bounds to avoid accessing elements outside the valid range, which can lead to undefined behavior.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Comments

Tags

Swagger UI
Swashbuckle
SwashbuckleAspNetCore
Rest API
Postman
Api Testing
ITextSharp
Export to Pdf
AspNet Core
AspNet
C#
View to Pdf in Aspnet
Scheduler
Fibonacci series in Java
Display Fibonacci Series
First C# Program
What is C?
C
C Programming
CodeLobster
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, India   info@code2night.com

Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • XML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • PDF Editor
By Language
  • Angular
  • C
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Built with for developers