C++/C++ dynamic memory allocation
Hi Mr. Dharmendra
Many thanx for ur reply. I tried ur solution.
It worked properly. but i get stuck in new problem.
I started as :
// Now when i tried to assign some random value to each of them
// using rand()%.. defined in stlib.h as:
It was giving unexpected runtime error , i was unable to trace it.
Plz help me
Hi, I am a new C++ programmar. I want to know how to dynamically allocate
memory for 2 dimentional array.
E.g. int a;
how can be such memory be allocated using 'new' operator.
(i'll thankful if u tell how to do using malloc)
using namespace std;
x = new int * ;
// x = (int **) malloc (sizeof(int *) * 10);
for (int i = 0 ; i < 10; i++)
x[i] = new int ;
// x[i] = (int *) malloc (sizeof(int) * 10);
for (i = 0 ; i < 10; i++)
delete  x[i];
// free x[i];
delete  x;
// free delete x;
problem is with the following while loop:
Please do not use the post increment operator there as it is missing out i = 0 and is starting from i = 1. you would be suprised as it is post increment operator not pre one but that explanation is also a big one so some other point of time.