Home > Blockchain >  what does this vector syntax mean in C ?
what does this vector syntax mean in C ?

Time:07-23

i am new to C and I was wondering what the below code does. I tried googling but could not find the answer. Thanks

vector<int> dist(n, INT_MAX);

CodePudding user response:

The line of code serves to declare a variable called dist, and to initialise it is a std::vector object.

The <int> part of the vector initialisation is called a template argument. The std::vector class is templated, which means it can store any arbitrary data-type, which is why the type has to be declared within angled brackets <>.

As mentioned in the comments, n and INT_MAX are values being passed to one of the constructors of the std::vector. It is only one of the constructors, since there are various different overloads of the constructor (check out the documentation in the comments to your question to read about the different available constructors).

Function (and also method) overloading is when you declare various functions with the same name, but that differ in the number and/or types of parameters that can be passed to them (the return type can also vary).

CodePudding user response:

Vector is a container C has already prepared.

I guess u should read the manual of STL before u use the class in it. And next is the answer;

Vector just like a string,but it has built many useful functions in it which make programers more inclined to use.

vector<int> dist(n, INT_MAX); the template is vector<type> name().

(n, INT_MAX) is initialization statement, it will put n INT_MAXs to the vector.

INT_MAX means largest number of type int;

If it helps you, please cast me a vote.

  • Related