blob: 212bb8b9c944b54c099202e9ac35b3bf9ce67e43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdlib.h>
#include <stdio.h>
int *foo(void) {
int *ptr = 0;
for (int i = 0; i < 5; i++) {
ptr = calloc(1, sizeof(*ptr));
}
ptr = calloc(1, sizeof(*ptr));
ptr = calloc(1, sizeof(*ptr));
*ptr = 5;
return ptr;
}
struct bar {
int x;
int *y;
};
int *bar(void) {
struct bar bar;
bar.x = 5;
bar.y = calloc(1, sizeof(int));
*bar.y = bar.x;
return bar.y;
}
int main(void) {
int *x = foo();
printf("Result of foo(): %d\n", *x);
x = bar();
printf("Result of bar(): %d\n", *x);
return 0;
}
|