I have to clear one doubt which has same concept in c and c++ as well.
Suppose i have a struct like this:
struct Huffman
{
int value;
unsigned char sym; /* symbol */
struct Huffman *left,*right; /* left and right subtrees */
};
typedef struct Huffman Node;
Node * tree;
and now i create tree using tree variable. Then using dot operator and arrow operator both. like this.
Arrorw operator:
for (i = 0; i < data_size; i++)
{
// the problem is here this tree pointer don't store the values for all alphabets, it just remembers the last executed alphabet after this for loop.
tree -> left = NULL;
tree ->right = NULL;
tree -> symbol = storesym[i];
tree -> freq = storefreq[i];
tree -> flag = 0;
tree -> next = i + 1;
cout<<"check1 : "<<tree -> symbol<<endl;
}
Dot Operator:
for (i = 0; i < data_size; i++)
{
tree[i].symbol = storesym[i];
tree[i].freq = storefreq[i];
tree[i].flag = 0;
tree[i].left = tree[i].right = tree[i].value = NULL;
tree[i].next = i + 1;
}
Now i am not able to understand that (1) what is the difference between the two ? (2) How they are allocated in memory ?