I am doing a little experiment with boolean data type in cpp. here is my code:
bool **darray;
darray=new bool* [3];
int i=0;
while(i<3)
{
darray[i]=new bool [5];
i++;
}
int m,n;
for(m=0;m<3;m++)
{
for(n=0;n<5;n++)
{
cin>>darray[m][n];
}
}
for(m=0;m<3;m++)
{
for(n=0;n<5;n++)
{
cout<<darray[m][n]<<"\t";
}
cout<<endl;
}
I know that for any non-zero input the result stored will be 1. But soon as I enter any number greater than 1, the number stored in array is 1, rest of the elements of the array is set to 0 and the for loops halts there. e.g If I enter the number 95 at first iteration of for loop, the output is :
95
1 0 0 0 0 //
0 0 0 0 0 // This is output
0 0 0 0 0 //
Please suggest me why this is happening. Thanks in Advance.
std::arrayelse "normal" arrays likebool array[3][5];. If you need arrays of dynamic size, considerstd::vector. You already have four memory leaks in your shown code.