int main()
{
int* Pointer;
Pointer = (int*) malloc(sizeof(int));
*Pointer = 33;
int* Pointer2 = Pointer;
printf("%d\n", *Pointer);
free(Pointer);
free(Pointer2);
return 0;
}
The output is 33 with no errors or warnings.
I declared two pointers that are pointing to the same heap address.
I know it's wrong to free them both and it is sufficient to only free one. Is it undefined if I free them both and will it do anything wrong if I free the same heap area from different pointers (Pointer
and Pointer2
)?