i want to dynamically allocate the array. program 1:
#include <iostream>
using namespace std;
int main()
{
int m,n;
cout<<"enter the no of rows and column for dynamic array:";
cin>>m>>n;
int ptr[m][n];
}
program 2:
#include <iostream>
using namespace std;
int main()
{
int m,n;
cout<<"enter the no of rows and column for dynamic array:";
cin>>m>>n;
int **ptr;
ptr=new int *[m];
for(int i=0;i<m;i++)
{
ptr[i]=new int [n];
}
}
its giving problem in the program 1: expression must have a constant value. the value of variable "m" cannot be used as a constant. the value of variable "n" cannot be used as a constant.
I was using that type of program before but it did not gave me this problem before. I am using g++ compiler. I tried changing the compiler and reinstalling mingw