3. To get to the value, you will have to first cast the void* to a pointer to the type originally used to initialize it, before erasure. The type of &p was void**, so that what you'd cast to:
1 2 3 4 5 6 7
#include <iostream>
int main()
{
void* p = &p;
std::cout << "address: " << p << '\n'
<< " value: " << *static_cast<void**>(p) << '\n';
}
Two pointers can point to each other, but pointing "to a structure called Node" is a completely different question. It would help if you described what you're really stuck on.
well..i want that initially both these pointers point to each other.
then if i call an insert_node function, then the function will create a node and will insert it between start and stop so that now, start and stop will both point to this node.
then, again if i call insert_node function, then it will again create a node and insert it between start and the node previously created so that now, start points to new node and stop points to old node.
actually ..this all happens in linked list.
But my problem is how to set the start and stop pointers pointing to each other initially.
> But I can't imagine a use for that.
Identifying an special node in a structure. By instance, the root on a tree.
Or a special condition. By instance, an empty list is the `header' node pointing to itself.
start->next = stop; however `start' is unititialized, so kaput.
@OP: you really should encapsulate the nodes. Create a `list' class to contain them.
1 2 3 4 5
class list{
private:
struct node{/**/};
node header;
};
well..i want that initially both these pointers point to each other.
then if i call an insert_node function, then the function will create a node and will insert it between start and stop
A pointer of type node* is either pointing at a node, or is null (pointing at nothing). To identify the special condition "the linked list is empty", you can either set both pointers to null or make them both point at some special placeholder node. They can't point to each other meaningfully.
Note that I'm using object instead of pointers for start and stop.
The advantage of this approach is that you could never dereference an invalid pointer, so you don't need to check for that in the operations.