R
Rick
Hi,
I'm trying to use a dynamic array but for some reason it won't work. This is
my code :
int *test;
int numElements = 2;
test = (int *) malloc (numElements * sizeof(int));
if (test= NULL) printf("Can't allocate\n"); // Nothing happens here
so it's ok I guess
test[0] = 10; // <- CRASH!
printf( "test= %d\n",test[0] );
I copied it from the internet and it seems that they all do it this way?
Then why won't this work? My computer sure has enough for 2 integers...
Greetings,
Rick
I'm trying to use a dynamic array but for some reason it won't work. This is
my code :
int *test;
int numElements = 2;
test = (int *) malloc (numElements * sizeof(int));
if (test= NULL) printf("Can't allocate\n"); // Nothing happens here
so it's ok I guess
test[0] = 10; // <- CRASH!
printf( "test= %d\n",test[0] );
I copied it from the internet and it seems that they all do it this way?
Then why won't this work? My computer sure has enough for 2 integers...
Greetings,
Rick