Will free()
work correctly if I change pointer the following way?
ar_byte_100=calloc(100,1);
ar_byte_100=&((unsigned long int*)ar_byte_100)[50];
free(ar_byte_100);
Will free()
work correctly if I change pointer the following way?
ar_byte_100=calloc(100,1);
ar_byte_100=&((unsigned long int*)ar_byte_100)[50];
free(ar_byte_100);
No.
You must pass the exact pointer returned by malloc()
or calloc()
to free()
.
According to the standard free(ptr)
ptr
should be a pointer returned by malloc()
calloc()
and realloc()
anything other than that is a undefined behavior.