Skip to content

Search topics & cppreference

Search all study topics, concept maps, and 6,587 C++ and C reference pages.

std::valarray<T>::resize

Resizes the valarray to contain count elements and assigns value to each element.

NotebookLM
void resize( std::size_t count, T value = T() );

Resizes the valarray to contain count elements and assigns value to each element.

This functions invalidates all pointers and references to elements in the array.

Parameters

count - new size of the container
value - the value to initialize the new elements with

Return value

(none)

Example

example.cpp
#include <iostream>
#include <valarray>
 
int main()
{
    std::valarray<int> v{1, 2, 3};
    v.resize(10);
    for (int n : v)
        std::cout << n << ' ';
    std::cout << '\n';
}
Output
0 0 0 0 0 0 0 0 0 0

See also

returns the size of valarray
(public member function)

Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.