Please figure out the error in the code and how to correct it ?
Actually i want to use a 2d dynamic array.

# include <iostream>
using namespace std;
int main()
{
    int number_of_rows = 0;
    int number_of_cols = 0;
    int a=0;

    cout<<"Please enter the no. of rows : ";
    cin>>number_of_rows;
    cout<<"Please enter the no. of rows : ";
    cin>>number_of_cols;

    int* seats = new int[number_of_rows * number_of_cols];

    for(int i=0;i<number_of_rows;i++)
    {
    for(int j=0;j<number_of_cols;j++)
    {   
            if(seats[i][j]==0)
                ++a;
    }
    }
cout<<"The total number of reserved seats is :  "<<(number_of_rows * number_of_cols)-a<<endl;
cout<<"The total number of un-reserved seats is :  "<<a<<endl;
return 0;
}

Use [code] /* code here */ [/code]

Ok but please check the code and reply as soon as you can.

int main()
{
    int row = 10;
    int col = 4;

    // col of pointers to rows
    int **dynamicArray =  new int *[col] ;

    // array for each row
    for( int i = 0 ; i < col; i++ )
    {
        dynamicArray[i] = new int[row];
    }

    // initialize with zero
    for( int c=0; c < col; c++ )
    {
        for( int r=0; r < row; r++ )
        {
            dynamicArray[c][r] = 0;
        }
    }

    return 0;
}

Bro, i can't properly understand the code. Please suggest me some site to learn about 2d pointer and 2d dynamic arrays. Thanks 4 ur help man.

I know about static array but i want to study 2d pointers and i can't find something good to read.

You might also want to consider a vector of vectors, which might be easier if your not familiar with pointers


std::vector< std::vector<int> > row;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.