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

