[Solved] What does this code snippet do exactly?


The following line:

vector<int> clusters(k,0);

Defines a random-access collection of k total integers each with an initial value of 0. clusters[id] accesses the integer value stored at index id in the vector. clusters[id]++ increments the integer value stored at index id. This works because operator [] on a vector returns a reference to the indexed item, allowing modification.

1

solved What does this code snippet do exactly?