A pointer stores a memory address. If you have declared a variable and a pointer to that variable, the pointer will store the address of the variable pointed by it. Below, an example with comments.
int a = 1; // allocated at 0x100, content is 1.
int* ptrA = &a; // allocated at 0x200, content is 0x100 (address of 'a')
In order to access the content of 'a' through the pointer, you have to dereference it, which is done with the dereference operator (*).
printf("'a' content is %d", *ptrA);
A pointer to a pointer also stores a memory address, but in this case, the memory address of another pointer. If you have declared a variable, a pointer to that variable and a pointer to the pointer of that variable, the first pointer still stores the address of the variable as in the first example, and the last pointer stores the address of the first pointer. Below, an example with comments.
int a = 1; // allocated at 0x100, content is 1.
int* ptrA = &a; // allocated at 0x200, content is 0x100 (address of 'a')
int** ptrToPtrA = &ptrA; // allocated at 0x300, content is 0x200 (address of 'ptrA')
In order to access the content of 'a' through the pointer to the pointer, you have to dereference it, once for retrieving the content of the pointer to pointer 'ptrToPtrA' (the pointer 'ptrA') and from here, once for retrieving the content of the pointer 'ptrA' (the variable content '1').
printf("'a' content is %d", **ptrToPtrA);
Below, a last example with comments, closer to your original question.
#include <stdio.h>
int main(void)
{
// pointer to char (stores the address of a char)
char* x = "abc";
printf("'x' address is #%p, content is %c\n", x, *x);
// pointer to pointer to char (stores the addres of a pointer to char)
char** xPtr = &x;
printf("'xPtr' address is #%p, content is %p\n", xPtr, *xPtr);
printf("'x' content through 'xPtr' is %c\n", **xPtr);
return 0;
}
char *x = "abc";is not a good idea."abc"is an array ofconst chars. Make thatconst char *x = "abc";int * y = &x;supposed to do in your mind? What is the double dereferencing ofysupposed to do? Where to you think you're ending up then?