+ 1

Linked List in C

Good morning/afternoon/evening everyone ! https://code.sololearn.com/cdyGRqAQvZFs/?ref=app I passed a reference to the pointer linked_list from main() function to show() function, then I changed its value (address).. I don't understand why, after the execution of show(), linked_list is not pointing to NULL (0) and still pointing to the head of the linked list. This is the output: Number of Elements: 3 Element 1: 5 Element 2: 8 Element 3: 2 BP1: linked_list is at 43f610 Linked list contains: 5 8 2 BP2: linked_list is at 0 BP3: linked_list is at 43f610 Can anyone please explain why ? And thanks in advance :)

15th Jul 2020, 12:23 PM
Tarek Hammami
Tarek Hammami - avatar
2 Réponses
0
nihil Yes you did :)))) Thank you so much ! I also googled the use of a pointer to a pointer since this is new to me to better understand it and I came up with the following example: #include<stdio.h> int main() { int n = 5, * p = &n, ** pp = &p; printf("n = %d", n); printf("\n&n = %d", &n); printf("\n\np = %d", p); printf("\n&p = %d", &p); printf("\n*p = %d", *p); printf("\n\npp = %d", pp); printf("\n&pp = %d", &pp); printf("\n*pp = %d", *pp); printf("\n**pp = %d", **pp); return 0; } The output is: n = 5 &n = 2293324 p = 2293324 &p = 2293312 *p = 5 pp = 2293312 &pp = 2293304 *pp = 2293324 **pp = 5 Again.. Thank you so much, sir or madam, for your explanation. :)
15th Jul 2020, 4:25 PM
Tarek Hammami
Tarek Hammami - avatar
0
nihil Thanks ! You too. Happy coding and have a nice day :)
15th Jul 2020, 4:34 PM
Tarek Hammami
Tarek Hammami - avatar