Binary arrays C++

Posted under C++ Course On By mohammed.mutawe

binary arrays

Binary arrays are frustrating for new C++ students and sometimes hinder their progress in understanding how the language works, so we will quickly explain the components of binary array and how they work.


Array: It is a variable of any type that can be classified as a variable of type int, string or char, where you can reserve a storage memory for a specific number that you put in that array, for example int a = [5], note here that we have reserved a single array that contains 5 places are reserved in memory.



All arrays are based on storing and extracting data through iterative loops, but what if we want to reserve a binary array in this form int a = [5][3], the situation is not as complicated as you think because in all cases, unary arrays need an iterative loop to pass and print all the elements, In binary matrices, the difference is that we will need two iterative loops.


Use of arrays in C++

The need is a proof and proof of invention. C++’s dependence on arrays is very important, specifically in the dynamic memory system, as it is frequently used in operating systems, games, search engines, audio and video modification, etc., which prompted language developers to create and develop arrays permanently.


The working principle of compiler in binary arrays

We will simplify the explanation as little as possible. Imagine that you see a table containing 3 rows and 6 columns, and you want to distribute values ​​randomly inside it. You will make an external iterative loop that contains the number of rows, because the translator’s passage will be faster on the columns in each row, and in Inside that loop, it will make another loop inside it. The compiler terminates the counter of the inner loop, then moves to the upper loop, and after the condition of the outer loop is finished, it will enter the execution of the inner loop again with new values ​​and an empty counter.

Are there ternary and quaternary arrays in C++?

In fact, yes there is, but its use is little, but triple loops can be implemented in large projects such as Directx projects, for example when called , It also hinders the thinking of the human mind when we use it in our code.




Please copy these codes to your editor to understand arrays correctly.

using namespace std;

int main() {
    const int rows = 3;    const int column = 6;

    int arr[rows][column];
    for (int i = 0; i < rows; i++) {

        for (int c = 0; c < column; c++) {

            cout << "Enter Element Is row num [" << i << "] and Column Num [" << c << " ] :"; cin >> arr[i][c];

    for (int i = 0; i < rows; i++) {

        cout << endl;
        for (int c = 0; c < column; c++) {
            cout << arr[i][c] << " ";

    return 0;


Leave a comment

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