【c】c pointer

double pointer
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
#include<stdio.h>
#include<stdlib.h>
int change_ptr(int** ptr);
int main()
{
//int local =3;
int *p =NULL;
//*p = local;
//printf("old *p =%d",p);
printf("old p =%p\n",p);
//printf("old =%p",p);
change_ptr(&p);
printf("*p=%d\n",*p);
printf("new p =%p\n",p);

return 0;
}
int change_ptr (int **ptr)
{
int *tmp = NULL;
tmp = malloc(sizeof(int));
*tmp = 4 ;
*ptr = tmp ;
return 0;
}

Makefile:

1
2
3
4
5
6
7
make:
gcc -g hello_rpms.c -o hello_rpms
clean:
rm hello_rpms
install:
mkdir -p ${DESTDIR}/usr/bin
install -m 0755 hello_rpms ${DESTDIR}/usr/bin/hello_rpms