I wrote this piece of code that I am not sure exactly how it works, but it works. This is the code:
struct node
{
string data;
node *chain;
};
int tablesize=10;
node *ptr [tablesize];
for (i=0; i<tablesize; i++)
{
ptr[i]=new node;
ptr[i]->data="Empty";
ptr[i]->chain=NULL;
}
If I understand it correctly, first I create an array of 10 pointers, then I assign each pointer with a new node? Why does it work only when I dereference it twice though? ( ptr[i]->data="Empty";)
ptr[i]is a pointer. You are not de-referencing twice. BTW you are using variable length arrays (VLAs), which are not standard C++.