Introduction
A pointer of another pointer is a type of pointer that points to another pointer. This type of pointer is useful when dealing with complex data structures, such as linked lists and trees. It can also be used to pass pointers to functions as parameters. In this article, we will discuss the concept of a pointer of another pointer, how it works, and how to use it in C programming. We will also look at some examples of how to use this type of pointer.
Solution
#include
int main()
{
int a = 10;
int *p;
int **pp;
p = &a;
pp = &p;
printf(“Value of a = %d\n”, a);
printf(“Value of *p = %d\n”, *p);
printf(“Value of **pp = %d\n”, **pp);
return 0;
}
In the printf
call you’re casting the value of B
to char *
, but that’s not what you assigned to it. You assigned &A
which has type char **
.
You need to either assign A
to B
:
void *B = A;
printf("%p -- %p -- %s -- %s", (void *)&A, (void *)B, A, (char *) B);
Or cast B
to a char **
and dereference the casted pointer:
void *B = &A;
printf("%p -- %p -- %s -- %s", (void *)&A, (void *)B, A, *(char **)B);
0
solved C Pointer of another pointer
Solved: C Pointer of Another Pointer Code
Pointers are a powerful tool in C programming, allowing us to manipulate data stored in memory. They can be used to store the address of a variable, or to point to another pointer. In this article, we will discuss how to use a pointer of another pointer in C.
A pointer of another pointer is a pointer that points to the address of another pointer. This can be useful when we want to access the data stored in a pointer without having to directly access the pointer itself. For example, if we have a pointer to an array of integers, we can use a pointer of another pointer to access the elements of the array without having to directly access the pointer.
To create a pointer of another pointer, we first need to declare a pointer to the pointer we want to access. This is done by using the asterisk (*) operator. For example, if we have a pointer to an array of integers, we can declare a pointer to the pointer as follows:
int **ptr;
Once we have declared the pointer to the pointer, we can use the address-of operator (&) to get the address of the pointer. For example, if we have a pointer to an array of integers, we can get the address of the pointer as follows:
ptr = &array;
Now that we have the address of the pointer, we can use the dereference operator (*) to access the data stored in the pointer. For example, if we have a pointer to an array of integers, we can access the elements of the array as follows:
int i = *(*ptr + i);
Using a pointer of another pointer can be a useful tool when we want to access the data stored in a pointer without having to directly access the pointer itself. It can also be used to create a linked list, where each element of the list is a pointer to another element.
We hope this article has helped you understand how to use a pointer of another pointer in C. If you have any questions or comments, please feel free to leave them in the comments section below.