Multidimensional Arrays - learnit

Home Top Ad

Post Top Ad

Sunday, August 2, 2020

Multidimensional Arrays

Array C Programming and Multidimensional Arrays

What is C Programming

C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on. This makes C++ powerful as well as flexible


-C++ is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance.


-After learning C++, it will be much easier to learn other programming languages like Java, Python, etc.


-C++ helps you to understand the internal architecture of a computer, how computer stores and retrieves information.


Array C Programming and Multidimensional Arrays

    C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.


    Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index.


    All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.


Declaring Arrays

    To declare an array in C++, the programmer specifies the type of the elements and the number of elements required by an array as follows.


Syntax"

Type arrayName [arraysize]

    This is called a single-dimension array. The arraySize must be an integer constant greater than zero and type can be any valid C++ data type.


Example

int salary[5]

Initializing Array

    You can initialize C++ array elements either one by one or using a single statement as follows.

        int salary[5]={200,300,340,500,400}


    The number of values between braces { } can not be larger than the number of elements that we declare for the array between square brackets [ ]


C++ MULTIDIMENSIONAL ARRAYS

A0 Col1 Col2 Col3 Col4
Row1 A0[0][0] A0[0][1] A0[0][2] A0[0][3]
Row2 A0[1][1] A0[1][1] A0[1][2] A0[1][3]
Row3 A0[2][0] A0[2][1] A0[2][2] A0[2][3]
Row4 A0[2][0] A0[2][1] A0[2][2] A0[2][3]


Example

#include <iostream>
using namespace std;
int main()
{
int a[3][4][4]={
{
{4,4,5,6 },
{6,7,8,9},
{10,4,6,7},
{4,5,6,7 }
},

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad