using realloc()

From: John Hanley (jdhanley_at_telusplanet.net)
Date: 07/30/04


Date: Thu, 29 Jul 2004 16:33:15 -0600

This is my first shot at ever using realloc and I think I've used it wrong
somehow.

I start out with int * elements = (int *) malloc(sizeof(int)),

then in my next function, I pass it 'elements' which I reallocate memory for
in order to add another element dynamically:

elements=(int *)realloc(elements, sizeof(int)*(j+1));

When debugging this in gdb, I notice that when j=2, and I realloc, my
address of 'elements' changes. But when j=1, it was fine.

Any ideas as to how I am using this incorrectly?

Thanks so much!

John