Message from C, C++ talks

July 2019

— I saw this on stackoverflow but i dont have any idea of this concept

IS there any other way

— Which one? Do you use C or C++?

— C++

— Well, std::vector is a template-based wrapper on dynamically allocated arrays, that you can resize dynamically, and use lots of things like alghorithms from STL. Also it has nice optimizations that go out of the box.

To use it you basically create an std::vector object giving it your type. Like std::vector<int> is something like a dynamic array of int elements.

Then you can work with it as with any array via square brackets. Or use other things like iterators. You can get the current size of array calling size function on it.

What else is not clear?

Message permanent page


Other way would be to have a very big array and use only part of it (store the size that you're actually using in another variable).

— But that comes with wasting memory and size limitations.

— How would i access it?

array[vector<int>] ??

— This is kind of what i wanted

— You could open the second link I gave you. It contains working examples

— YEs I know but I am solving a small problem for hackerrank

— Okay
I will see

— Thanks!

— Ops, I meant the first link

— 👍

— Vector is the easiest way to do such thing, I highly recommend to have a look at it. As you anyway will find this type in almost every non trivial C++ program.

Message permanent page