-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetme.c
100 lines (64 loc) · 1.05 KB
/
getme.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<stdio.h>
/*void add(x)
{
x=x+1;
}
void main()
{
int a=1;
add(a);
printf("%d",a);
}
char *GetMemory3(int num)
{
char *p = (char *)malloc (sizeof(char) * num);
printf("%d",p);
return p; //返回指针 p
}
void main(void)
{
char *str = NULL;
str = GetMemory3(100); //这里指针 str也和指针 p的指向一样的内存块。
printf("%d",str);
strcpy(str, "hello");
printf(str);
}*/
char *GetMemory2(void)
{
char p[] = "hello world";
printf("%d",p);
return p;
}
void main(void)
{
char *str = NULL;
str = GetMemory2();
printf("\n%d",str);
printf(str);
}
/*
void GetMemory1(char *p)
{
p = (char *)malloc(100);
}
void main(void)
{
char *str = NULL;
GetMemory1(str);
strcpy(str, "hello world");
printf(str);
}
void main(void)
{
char *str = (char*)malloc(100);
strcpy(str, "hello");
printf("%d\n",str);
free(str);
printf("%d",str);
if (str != NULL)
{
strcpy(str, "world");
printf(str);
}
}
*/