Am I doing the free() wrong........?

Check the following code and its o/p -

int* p[3];

for(int ji = 0; ji< 3 ; ji++) {

p[ji] = (int*)malloc(sizeof(int));

*(p[ji]) = i;

}

...

...

...

for(int ii = 0; ii< 3 ; ii++) {

printf("Freeing memory %x and its value %d\n", p[ii],*p[ii]);

free(p[ii]);

printf("Memory after freeing %x and its value %d\n",p[ii], *p[ii]);

}

O/P I get is -

Freeing memory 21180 and its value 0

Memory after freeing 21180 and its value 0

Freeing memory 21190 and its value 1

Memory after freeing 21190 and its value 1

Freeing memory 211a0 and its value 2

Memory after freeing 211a0 and its value 2

why the memory is not freed and why the value is displayed correctly after the memory is freed ?

-Jerry

[825 byte] By [jerryragland] at [2007-11-26 10:10:07]
# 1
Function 'free' just mark allocated block of memory as unused and usually does not to do anything with content of this memory block.Here is a good article http://en.wikipedia.org/wiki/Malloc.
Atanasyan at 2007-7-7 1:54:30 > top of Java-index,Development Tools,Solaris and Linux Development Tools...