Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Pointer to Pointer | Section
C Pointers Mastery

bookPointer to Pointer

Sometimes you do not just want to change a value, you want to change it through another pointer. That is where a pointer to pointer comes in. Think of it like this:

  • int x holds a number;
  • int *p holds the address of x;
  • int **pp holds the address of p.

So the chain looks like:

pp → p → x → value

To reach the real value, you must dereference twice.

main.c

main.c

copy
12345678910111213141516
#include <stdio.h> void set_to_ten(int **pp) { **pp = 10; } int main() { int x = 5; int *p = &x; int **pp = &p; set_to_ten(pp); printf("%d\n", x); // prints 10 return 0; }

So basically you are setting the original variable x to 10 through two pointer levels. This is exactly what you need for the multi-level pointer task.

Note
Note

Pointer-to-pointer logic is most useful when a function must modify data that is already accessed through a pointer. If you forget one * when dereferencing, the program will compile but update the wrong level, so always double-check how many pointer layers you are working with.

question mark

What does dereferencing a pointer to pointer (*pp) return in the context where int x; int *p = &x; int **pp = &p;?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 10

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookPointer to Pointer

Свайпніть щоб показати меню

Sometimes you do not just want to change a value, you want to change it through another pointer. That is where a pointer to pointer comes in. Think of it like this:

  • int x holds a number;
  • int *p holds the address of x;
  • int **pp holds the address of p.

So the chain looks like:

pp → p → x → value

To reach the real value, you must dereference twice.

main.c

main.c

copy
12345678910111213141516
#include <stdio.h> void set_to_ten(int **pp) { **pp = 10; } int main() { int x = 5; int *p = &x; int **pp = &p; set_to_ten(pp); printf("%d\n", x); // prints 10 return 0; }

So basically you are setting the original variable x to 10 through two pointer levels. This is exactly what you need for the multi-level pointer task.

Note
Note

Pointer-to-pointer logic is most useful when a function must modify data that is already accessed through a pointer. If you forget one * when dereferencing, the program will compile but update the wrong level, so always double-check how many pointer layers you are working with.

question mark

What does dereferencing a pointer to pointer (*pp) return in the context where int x; int *p = &x; int **pp = &p;?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 10
some-alt