Simple declaration, value putting and direct value display from 2D array – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #CPP#7527    siteicon   siteicon  

Simple declaration, value putting and direct value display from 2D array

A simple code to declare a 2D array, direct value putting and value recall.

Learning Objectives

  • Understanding simple declaration 2D array.
  • Direct insertion and recall of data from a 2D array.

Source Code

TC++ #7527


Source Code

Run Output


Code Understanding

int arr[2][3];
Here we are simply declaring a 2D array with expected 6 integer data members in 2 row and 3 column form.

arr[0][0]=10; //We are putting value 10 at row 0 and col 0 index.
arr[1][2]=20; //We are putting value 20 at row 1 and col 2 index
cout<<arr[0][0]<<endl; //We are recalling the value inserted by us at 0,0
cout<<arr[1][2]<<endl; //We are recalling value inserted by us at 1,2
cout<<arr[1][1]<<endl; //We are recalling an un-initialised value

The un-initialised values may keep a junk value or 0 as per the environment/compiler


  • A declaration with initialisation does need to specify both bounds of a 2D Array like
    int arr[2][3]; and not int arr[][3];
  • Any number of dimensions can be given to an array for ex.
    int arr[2][3][1][4]; is also possible and is a 4 dimensional array.

Common Errors

  • Typically all array members should be given some initial values to avoid any unwanted junk values.

Suggested Filename(s): dec-ins-recall.cpp,decinsre.cpp


CSKC| Created: 15-Oct-2019 | Updated: 15-Oct-2019|

Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues