C Programming

⌘K
  1. Home
  2. Docs
  3. C Programming
  4. Arrays and Strings
  5. Declaration and Memory Representation of Array

Declaration and Memory Representation of Array

Syntax:

data_type array_name[size];

Example (1D Array):

int numbers[5];
  • This declares an array of 5 integers. Each element is accessed using an index:

Example (2D Array):

int matrix[3][4];
  • This declares a 2D array with 3 rows and 4 columns, capable of holding 12 integers.

One-Dimensional Array:

int a[5] = {10, 20, 30, 40, 50};

Memory Representation (assuming base address = 1000 and int = 4 bytes):

image
  • Contiguous memory means all elements are stored one after another.

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *