Reputation: 130
What is *table[17] in the given code? Does it just make 17 copies of the structure?
struct node
{
string key;
string no;
node *next;
}*table[17];
Upvotes: 0
Views: 58
Reputation: 5591
What is *table[17]?
The meaning of this line of code ...}*table[17];
is, you have defined a struct node
and declared an array of type node pointer
and size of that pointer array is to store 17 node element/object pointers. So in table array you can store the address of 17 node elements.
For example:-
struct node a, b, c, d ....,p;
table[0] = &a;//storing the address of a;
table[1] = &b;//storing the address of b;
table[2] = &c;//storing the address of c;
.
.
.
table[16] = &p;//storing the address of p;
or dynamically:-
for( int i = 0; i < 17; i++)
table[0] = new node();// in C (struct node *) malloc(sizeof(struct node));
Does it just make 17 copies of the structure?
No it is just an array of 17 pointers. You have to assign the address of element of type node in each location. Hence you have to create each node element like I did above. Hope this will help you.
Upvotes: 2
Reputation: 238341
What is the meaning of *table[17]?
It is a declarator. It declares a variable of type *node[17]
with name table
. That is an array of 17 pointers to node
.
Does it just make 17 copies of the structure?
No. No node
objects will be made.
Upvotes: 5