1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
int a = 10, b = 1;
int* aptr = NULL;
// double * dptr = &a;
aptr = &a; // aptr -> a, a = 10, b = 1
*aptr = b; // aptr -> a, a = 1, b = 1
a = 2; // aptr -> a, a = 2, b = 1
b = 7; // aptr -> a, a = 2, b = 7
&a = b; // aptr -> old a, old a = 2, b(a) = 7;
printf("%d %d", a, *aptr); // 7 2
int * potato = NULL;
if(potato == NULL)
printf("hi");
potato = (int *)malloc(sizeof(int) * 127);
if(potato == NULL)
printf("Memory allocation failed.\n");
potato = NULL;
if(potato != NULL)
free(potato);
potato[4] = 4; // *(potato + 4) = 4;
|