From 476671741bb07085eec851702a7c3b1e5a4cc0ba Mon Sep 17 00:00:00 2001 From: Gitea Date: Sat, 15 Jan 2022 11:50:27 +0800 Subject: [PATCH] add check_pointer.c --- check_pointer.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 check_pointer.c diff --git a/check_pointer.c b/check_pointer.c new file mode 100644 index 0000000..cc94dee --- /dev/null +++ b/check_pointer.c @@ -0,0 +1,61 @@ +#include + +int main() +{ + int a = 1; + int b = 2; + int c = 3; + int d = 4; + + int *pa = &a; + int *pb = &b; + int **ppa = &pa; + int **ppb = &pb; + + printf("%x %x\n", &a, a); + printf("%x %x\n", &b, b); + printf("%x %x\n", &c, c); + printf("%x %x\n", &d, d); + printf("%x %x %x\n", &pa, pa, *pa); + printf("%x %x %x\n", &pb, pb, *pb); + printf("%x %x %x %x\n", &ppa, ppa, *ppa, **ppa); + printf("%x %x %x %x\n", &ppb, ppb, *ppb, **ppb); + + ppa = &pb; + ppb = &pa; + + printf("%x %x\n", &a, a); + printf("%x %x\n", &b, b); + printf("%x %x\n", &c, c); + printf("%x %x\n", &d, d); + printf("%x %x %x\n", &pa, pa, *pa); + printf("%x %x %x\n", &pb, pb, *pb); + printf("%x %x %x %x\n", &ppa, ppa, *ppa, **ppa); + printf("%x %x %x %x\n", &ppb, ppb, *ppb, **ppb); + + *ppa = &c; + *ppb = &d; + + printf("%x %x\n", &a, a); + printf("%x %x\n", &b, b); + printf("%x %x\n", &c, c); + printf("%x %x\n", &d, d); + printf("%x %x %x\n", &pa, pa, *pa); + printf("%x %x %x\n", &pb, pb, *pb); + printf("%x %x %x %x\n", &ppa, ppa, *ppa, **ppa); + printf("%x %x %x %x\n", &ppb, ppb, *ppb, **ppb); + + **ppa = 5; + **ppb = 6; + + printf("%x %x\n", &a, a); + printf("%x %x\n", &b, b); + printf("%x %x\n", &c, c); + printf("%x %x\n", &d, d); + printf("%x %x %x\n", &pa, pa, *pa); + printf("%x %x %x\n", &pb, pb, *pb); + printf("%x %x %x %x\n", &ppa, ppa, *ppa, **ppa); + printf("%x %x %x %x\n", &ppb, ppb, *ppb, **ppb); + + return 0; +}