The following is the memory layout of a pointer to a pointer.
Let's assume an 8 bit computer with 8 bit addresses (and thus only 256 bytes of memory). This is part of that memory (the numbers at the top are the addresses):
45 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | 58 | | | 63 | | 55 | | | h | e | l | l | o | \0 | |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
What you can see here, is that at address 63 the string "hello" starts. So in this case, if this is the only occurrence of "hello" in memory then,
const char *c = "hello";
... defines c to be a pointer to the (read-only) string "hello", and thus contains the value 63. c must itself be stored somewhere: in the example above at location 58. Of course we can not only point to characters, but also to other pointers. E.g.:
const char **cp = &c;
Now cp points to c, that is, it contains the address of c (which is 58).
________________________________________________________________________
What I would like is a brief memory layout of a pointer to a pointer of a node or struct of a linked list. What is the value of **head, *head, head in the insertFront routine. Hope Im not asking to much.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
struct node{
int data;
node *next;
};
void initNode(struct node *head,int nodeData)
{
head->data = nodeData;
head->next = NULL;
}
void insertFront(struct node **head,int frontData)
{
node *frontNode = new node;
frontNode->next = *head;
frontNode->data = frontData;
*head = frontNode;
int main()
{
node *head = new node;
initNode(head,10);
insertFront(&head,60);
return 0 ;
}
|