2
    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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

No, the array will be static throughout the course of the program. So my code would work, right?
Yes, it would work as-is, given your comment. Just be careful of using the word static (unchanging) - "static" has a specific meaning in C++ unrelated to its common definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.