diff --git a/7-pointers-arrays/CMakeLists.txt b/7-pointers-arrays/CMakeLists.txt index 191739e..e72df11 100644 --- a/7-pointers-arrays/CMakeLists.txt +++ b/7-pointers-arrays/CMakeLists.txt @@ -1,3 +1,4 @@ +add_executable(memory memory.c) add_executable(pointer pointer.c) add_executable(selection-sort-pointers selection-sort.c) add_executable(pointer-array pointer-array.c) diff --git a/7-pointers-arrays/memory.c b/7-pointers-arrays/memory.c new file mode 100644 index 0000000..0e221e0 --- /dev/null +++ b/7-pointers-arrays/memory.c @@ -0,0 +1,12 @@ +// Created by hfwei on 2024/11/15. + +#include + +int main(void) { + int i = 50; + + scanf("%d", &i); + printf("%d\n", i); + + return 0; +} \ No newline at end of file diff --git a/7-pointers-arrays/pointer.c b/7-pointers-arrays/pointer.c index 352be7b..4894fcd 100644 --- a/7-pointers-arrays/pointer.c +++ b/7-pointers-arrays/pointer.c @@ -36,8 +36,6 @@ int main(void) { int *ptr_radius_2 = &radius_2; ptr_radius_1 = ptr_radius_2; - *ptr_radius_2 = 2000; - printf("radius_1 = %d\n", *ptr_radius_1); /********** On ptr_radius_1 as lvalue and rvalue **********/ /********** On *ptr_radius_1 **********/ @@ -45,14 +43,29 @@ int main(void) { // *ptr_radius_1 behaves like radius_1 *ptr_radius_1 = 200; printf("radius_1 = %d\n", radius_1); + circumference = 2 * PI * (*ptr_radius_1); /********** On *ptr_radius_1 **********/ + /********** On types of pointers **********/ + int i = -1; + + unsigned int *ptr_i_double = &i; + printf("i = %u\n", *ptr_i_double); + + unsigned int hex = 0x44434241; + char *ptr_hex = &hex; + printf("i = %c\n", *ptr_hex); + printf("i = %c\n", *(ptr_hex + 1)); + /********** On types of pointers **********/ + + /********** On types of pointers (more) **********/ int v = 100; int *pv = &v; printf("pv : %p\n *pv : %d\n", pv, *pv); pv = &pv; printf("pv : %p\n", pv); + /********** On types of pointers (more) **********/ return 0; } \ No newline at end of file diff --git a/pdf/7-pointers-arrays.pdf b/pdf/7-pointers-arrays.pdf index 81b6312..aa548a7 100644 Binary files a/pdf/7-pointers-arrays.pdf and b/pdf/7-pointers-arrays.pdf differ diff --git a/template/7-pointers-arrays/7-pointer-array-template.pdf b/template/7-pointers-arrays/7-pointer-array-template.pdf new file mode 100644 index 0000000..7cf391c Binary files /dev/null and b/template/7-pointers-arrays/7-pointer-array-template.pdf differ diff --git a/template/7-pointers-arrays/memory.c b/template/7-pointers-arrays/memory.c new file mode 100644 index 0000000..0e221e0 --- /dev/null +++ b/template/7-pointers-arrays/memory.c @@ -0,0 +1,12 @@ +// Created by hfwei on 2024/11/15. + +#include + +int main(void) { + int i = 50; + + scanf("%d", &i); + printf("%d\n", i); + + return 0; +} \ No newline at end of file diff --git a/template/7-pointers-arrays/pointer.c b/template/7-pointers-arrays/pointer.c index 804e6af..acee6c6 100644 --- a/template/7-pointers-arrays/pointer.c +++ b/template/7-pointers-arrays/pointer.c @@ -10,14 +10,14 @@ int main(void) { // https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000740490-Where-did-the-black-windows-go-?page=1#community_comment_115000619510 // setbuf(stdout, NULL); - /********** On radius_1 **********/ + /********** On radius_1 as lvalue and rvalue **********/ int radius_1 = 100; printf("radius_1 = %d\n", radius_1); double circumference = 2 * PI * radius_1; printf("circumference = %f\n", circumference); - /********** On radius_1 **********/ + /********** On radius_1 as lvalue and rvalue **********/ /********** On ptr_radius_1 **********/ /********** On ptr_radius_1 **********/ @@ -28,5 +28,11 @@ int main(void) { /********** On *ptr_radius_1 **********/ /********** On *ptr_radius_1 **********/ + /********** On types of pointers **********/ + /********** On types of pointers **********/ + + /********** On types of pointers (more) **********/ + /********** On types of pointers (more) **********/ + return 0; } \ No newline at end of file