Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道在 C++ 中将数组初始化为零是否是个好主意,如下所示:
const int n = 100; double* x = new double[n]; cblas_dscal(n,0.0,x,1);
有任何想法吗?
不需要额外调用 mkl 函数。做就是了:
const int n = 100; double* x = new double[n]();
这是一个 C++ 功能,在此处进行了更详细的说明。
更好的是使用向量,它可以让您将初始值指定为可选参数(默认为 0)
std::vector<double> x(n, 0.0);