user2155612
user2155612

Reputation:

creating a dynamic array?

    keyMain= new Key_Node[X];
    for(int i=0; i<X; i++)
    {
        keyMain[i].key=i;
        cout << keyMain[i].key<<endl;
        keyMain[i].next_package=NULL;
    }

Am I doing it right here? I am not sure about it. It seems like the right thing to do, but can anybody confirm? Thank you.X is the number inputted by the user.

Upvotes: 2

Views: 93

Answers (1)

paxdiablo
paxdiablo

Reputation: 881463

Yes, you can certainly do that, provided the array is not expected to grow or shrink.

Otherwise, std::vector (see here) is probably a better choice. C++ provides some powerful collection classes in its standard library and everyone who professes to know the language should be familiar with them.

Upvotes: 3

Related Questions