@@ -5,7 +5,8 @@ C pointers are simple and enjoyable to learn.Some C programming tasks are easier
55* [ Addresses in C] ( #addresses-in-c )
66* [ What is Pointer?] ( #what-is-pointer )
77* [ Pointer Syntax] ( #pointer-syntax )
8- * [ Get value of things Pointed by Pointer] ( #get-value-of-things-pointed-by-pointer )
8+ * [ Get value of things Pointed by Pointers] ( #get-value-of-things-pointed-by-pointers )
9+ * [ Changing value Pointed by Pointers] ( #changing-value-pointed-by-pointers )
910
1011## Addresses in C
1112Before we get to the definition of pointers, let us understand what happens when we write the following code:
@@ -58,3 +59,31 @@ Here, the address of c is assigned to the pc pointer. To get the value stored in
5859*Note: In the above example, pc is a pointer, not * pc. You cannot and should not do something like * pc = &c;*
5960
6061*By the way, * is called the dereference operator (when working with pointers). It operates on a pointer and gives the value stored in that pointer.*
62+
63+ # Changing Value Pointed by Pointers
64+ Let's take an example.
65+ ```c
66+ int* pc, c;
67+ c = 5;
68+ pc = &c;
69+ c = 1;
70+ printf("%d", c); // Output: 1
71+ printf("%d", *pc); // Ouptut: 1
72+ ```
73+ We have assigned the address of c to the pc pointer.
74+
75+ Then, we changed the value of c to 1. Since pc and the address of c is the same, * pc gives us 1.
76+
77+ Let's take another example.
78+ ``` c
79+ int * pc, c;
80+ c = 5 ;
81+ pc = &c;
82+ *pc = 1 ;
83+ printf ("%d", * pc); // Ouptut: 1
84+ printf("%d", c); // Output: 1
85+ ```
86+ We have assigned the address of c to the pc pointer.
87+
88+ Then, we changed *pc to 1 using *pc = 1;. Since pc and the address of c is the same, c will be equal to 1.
89+
0 commit comments