Pointer to Pointer in C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

In C language, a pointer to a pointer is a type of pointer that holds the memory address of another pointer. It's represented by a double indirection operator (**). A pointer to a pointer is useful in situations where you need to pass a pointer to a function, but you also want the function to be able to modify the pointer itself.

Here's an example of a pointer to a pointer:

Copy code

#include <stdio.h> int main() {    int x = 10;    int* p = &x;    int** pp = &p;  // pp is a pointer to a pointer    printf("%d\n", **pp);  // prints 10    return 0; }

In this example, the variable x is an integer, p is a pointer that holds the memory address of x, and pp is a pointer to a pointer that holds the memory address of p. To access the value of x, we dereference pp twice, first as a pointer and then as an integer.

Here's an example of a function that takes a pointer to a pointer as an argument and modifies the pointer:

Copy code

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

In this example, the func function takes a pointer to a pointer pp as an argument. Inside the function, it creates a new integer y with the value 20, and assigns the address of y to the pointer pp points to, thus changing the value of p and the value it points to.

It's worth noting that, when working with pointer to pointer, you need to be

8. Pointers

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?