Created
October 23, 2014 06:07
-
-
Save gong023/72258725c92b9ad3e50a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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