Hi

I want to create an array as shown in the class below
everything is working fine, but at the end of execution of the program, there is a memory fault
Please help me in finding out the problem

class a
{
int i;
int arr[];
public:
a();
~a();
void disp();
};

a::a():i(10)
{
int j = 0;
for(; j < i; j++)
{
arr[j] = j;
cout<<"In constructor j value is "<<j<<endl;
}
}

a::~a()
{
}

void a::disp()
{
for(int j=0; j < i; j++)
{
cout<<arr[j]<<"\t";
}
cout<<endl;
}

int main() {

a obj;
obj.disp();
return 0;
}

Thanks
VADAN

Your array has no size.
My guess, it just trashes memory when you fill the first 10 non-existent slots.

thanks for all your reply
my problem got solved
i have used vectors to solve the above problem

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.