[Solved] Segmentation fault when calling a function returning a pointer
[ad_1] Let’s use std::vector: #include <iostream> #include <vector> #include <iomanip> typedef std::vector<double> DoubleArray; DoubleArray v_scalar_prod(double a, double *b, int n) { DoubleArray res(n); for (int i = 0; i < n; i++) { res[i] = a*b[i]; std::cout << std::setprecision(10) << “res = ” << res[i] << ‘\n’; } return res; } int main() { double … Read more