0

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

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by vadan
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.