Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Interview Questions on Array
  • Practice Array
  • MCQs on Array
  • Tutorial on Array
  • Types of Arrays
  • Array Operations
  • Subarrays, Subsequences, Subsets
  • Reverse Array
  • Static Vs Arrays
  • Array Vs Linked List
  • Array | Range Queries
  • Advantages & Disadvantages
Open In App
Next Article:
Difference between List and Array in Python
Next article icon

Difference Between one-dimensional and two-dimensional array

Last Updated : 02 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Array is a data structure that is used to store variables that are of similar data types at contiguous locations. The main advantage of the array is random access and cache friendliness. There are mainly three types of the array:

  • One Dimensional (1D) Array
  • Two Dimension (2D) Array
  • Multidimensional Array

One Dimensional Array: 

  • It is a list of the variable of similar data types.
  • It allows random access and all the elements can be accessed with the help of their index.
  • The size of the array is fixed.
  • For a dynamically sized array, vector can be used in C++.
  • Representation of 1D array:

Two Dimensional Array:

  • It is a list of lists of the variable of the same data type.
  • It also allows random access and all the elements can be accessed with the help of their index.
  • It can also be seen as a collection of 1D arrays. It is also known as the Matrix.
  • Its dimension can be increased from 2 to 3 and 4 so on.
  • They all are referred to as a multi-dimension array.
  • The most common multidimensional array is a 2D array.
  • Representation of 2 D array:

Difference Table:

Basis One Dimension Array Two Dimension Array
Definition Store a single list of the element of a similar data type. Store a ‘list of lists’ of the element of a similar data type.
Representation Represent multiple data items as a list. Represent multiple data items as a table consisting of rows and columns.
Declaration

The declaration varies for different programming language:

  1. For C++,  
    datatype variable_name[row]
  2. For Java,  
    datatype [] variable_name= new datatype[row]

The declaration varies for different programming language:

  1. For C++, 
    datatype variable_name[row][column]
  2. For Java,  
    datatype [][] variable_name= new datatype[row][column]
Dimension One Two
Size(bytes) size of(datatype of the variable of the array) * size of the array size of(datatype of the variable of the array)* the number of rows* the number of columns.
Address calculation. Address of a[index] is equal to (base Address+ Size of each element of array * index).

Address of a[i][j] can be calculated in two ways row-major and column-major

  1. Column Major: Base Address + Size of each element (number of rows(j-lower bound of the column)+(i-lower bound of the rows))
  2. Row Major: Base Address + Size of each element (number of columns(i-lower bound of the row)+(j-lower bound of the column))
Example

int arr[5];  //an array with one row and five columns will be created.

{a , b , c , d , e}

int arr[2][5];  //an array with two rows and five columns will be created.

               a  b  c  d  e

               f  g   h  i   j

Applications of Arrays:

  • 2D Arrays are used to implement matrices.
  • Arrays can be used to implement various data structures like a heap, stack, queue, etc.
  • They allow random access.
  • They are cache-friendly.


Next Article
Difference between List and Array in Python

C

CoderSaty
Improve
Article Tags :
  • Arrays
  • Difference Between
  • DSA
  • Technical Scripter
Practice Tags :
  • Arrays

Similar Reads

  • Difference between Array and Union in C
    1. Array in C : An array is collection of similar data items accessed by a common name stored at continuous memory locations. The elements of an array can be accessed using indices. They can be used to store primitive data types such as int, float, double, char, etc. but all elements have to be of t
    2 min read
  • Difference between List and Array in Python
    In Python, lists and arrays are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements. In this article, we will see the difference between the two. Operations Difference in Lists and ArraysAccess
    6 min read
  • What is the difference between lists and arrays?
    In programming, lists and arrays are data structures used to organize and store data. Both have their unique features and purposes. Lists are dynamic and flexible, allowing for easy resizing during runtime, while arrays are static with a fixed size. This difference impacts memory usage and performan
    8 min read
  • Difference between Array and String in Java
    An array is a collection of similar type of elements that are stored in a contiguous memory location. Arrays can contain primitives(int, char, etc) as well as object(non-primitives) references of a class depending upon the definition of the array. In the case of primitive data type, the actual value
    5 min read
  • Difference between Heaps and Sorted Array
    1. Heap:A heap is a tree based data structure in which tree should be almost complete. It is of two types i.e. max and min heap. Max heap: In max heap, if p is the parent and c is its child, then for every parent p the value of it is greater than or equal to the value of cMin heap In min heap, if p
    4 min read
  • Difference between Array and Map
    Array:An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of t
    12 min read
  • Difference between pointer to an array and array of pointers
    Pointer to an array: Pointer to an array is also known as array pointer. We are using the pointer to access the components of the array. int a[3] = {3, 4, 5 }; int *ptr = a; We have a pointer ptr that focuses to the 0th component of the array. We can likewise declare a pointer that can point to whol
    4 min read
  • Difference Between JavaScript Arrays and Objects
    Below are the main differences between a JavaScript Array and Object. FeatureJavaScript ArraysJavaScript ObjectsIndex TypeNumeric indexes (0, 1, 2, ...)Named keys (strings or symbols)OrderOrdered collectionUnordered collectionUse CaseStoring lists, sequences, ordered dataStoring data with key-value
    1 min read
  • Difference between Stack and Array
    Stack: A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into a
    3 min read
  • Difference between Array, Queue and Stack
    Array: An Array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences