Skip to content

Commit

Permalink
7-pointers-arrays/: +memory.c
Browse files Browse the repository at this point in the history
  • Loading branch information
hengxin committed Nov 15, 2024
1 parent bfd6bba commit 71afa54
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions 7-pointers-arrays/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions 7-pointers-arrays/memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Created by hfwei on 2024/11/15.

#include <stdio.h>

int main(void) {
int i = 50;

scanf("%d", &i);
printf("%d\n", i);

return 0;
}
17 changes: 15 additions & 2 deletions 7-pointers-arrays/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,36 @@ 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 **********/
// *: indirection/dereference operator
// *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;
}
Binary file modified pdf/7-pointers-arrays.pdf
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions template/7-pointers-arrays/memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Created by hfwei on 2024/11/15.

#include <stdio.h>

int main(void) {
int i = 50;

scanf("%d", &i);
printf("%d\n", i);

return 0;
}
10 changes: 8 additions & 2 deletions template/7-pointers-arrays/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 **********/
Expand All @@ -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;
}

0 comments on commit 71afa54

Please sign in to comment.