Skip to content

Instantly share code, notes, and snippets.

@gong023
Created October 23, 2014 06:07
Show Gist options
  • Save gong023/72258725c92b9ad3e50a to your computer and use it in GitHub Desktop.
Save gong023/72258725c92b9ad3e50a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct hoge { int num; };
int* pick_num(struct hoge *h)
{
int *copy = &h->num;
free(&h);
return copy;
}
int main(void)
{
struct hoge *x;
x = (struct hoge *) malloc (sizeof(struct hoge));
x->num = 5;
int *y = pick_num(x);
printf("%i\n", x->num);
printf("%i\n", *y);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment