If i initialize a std::vector
like this:
vector<int> sletmig(300);
will it set all the 300 values to zero, or keep what was in my computer memory?
If i initialize a std::vector
like this:
vector<int> sletmig(300);
will it set all the 300 values to zero, or keep what was in my computer memory?
They will be set to zero as the elements will be value-initialized.
From cppreference
explicit vector( size_type count );
Constructs the container with
count
default-inserted instances ofT
. No copies are made.
But know that you can also specify the default value of all the elements, for example
vector<int> sletmig(300, 0);
Again from cppreference
vector( size_type count,
const T& value,
const Allocator& alloc = Allocator());
Constructs the container with
count
copies of elements withvalue
value.