# std::valarray<T>::resize

> C++ Atlas: `cppatlas.com/w/cpp/numeric/valarray/resize` | Source: https://en.cppreference.com/w/cpp/numeric/valarray/resize | Domain: Numerics

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

## Official Specification Summary (cppreference)

```cpp
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

```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:

```text
0 0 0 0 0 0 0 0 0 0
```

### See also

- [`size`](https://en.cppreference.com/w/cpp/numeric/valarray/size): returns the size of valarray (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/numeric/valarray/resize (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.