initialize a vector with zeros c++ code example

Example 1: initialize 3d vector c++

vector<vector<vector<double>>> f(3, vector<vector<double>>(4, vector<double>(5)));

Example 2: how to initialize vector in c++ with all elements 0

vector<int> arr(10,0);

Example 3: initialize vector to all zeros c++

// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
// 1-D case
vector<int> vec(desiredVectorSize, 0);  

// 2-D case
vector<vector<int>> vec(desiredNoOfRows, vector<int>(desiredNoOfColumns, 0));

Tags:

Cpp Example