Skip to content

Instantly share code, notes, and snippets.

@sitano
Last active November 5, 2017 13:55
Show Gist options
  • Save sitano/0372e516aadf7bbecabc33f0b6516704 to your computer and use it in GitHub Desktop.
Save sitano/0372e516aadf7bbecabc33f0b6516704 to your computer and use it in GitHub Desktop.
undefined behavior with realloc
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int* p = (int *)malloc(sizeof(int));
int* q = (int *)realloc(p, sizeof(int));
*p = 1;
*q = 2;
if (p == q)
{
printf("%d %d\n", *p, *q);
}
return 0;
}