c++ - Issue with allocating memory for pointers -
i asking similar question earlier. answers got pinpointed mistake not having set aside memory pointer. following piece of code still complains error: cannot convert ‘void*’ ‘double’ in assignment. mean elements in array set aside null?
#include <cmath> #include <cstdlib> #include <fstream> #include <iostream> #include <vector> #include <stdio.h> #include <stdlib.h> using namespace std; int n = 2; int main(int argc, char *argv[]) { double *p[n]; for(int = 0; i<n; ++i){ *p[i]=malloc(sizeof(double)); } *p[0] = 1.0; *p[1] = 2.0; cout << p[0] << " " << p[1] <<endl; *p[0] = 5.0; *p[1] = 6.0; cout << p[0] << " " << p[1] <<endl; return 0;
}
i need array solve problem have. array needs in global memory (in cuda), needs pointer gpus can read/write from/to.
p[i]=malloc(sizeof(double));
..get rid of '*' dereferencing double type , trying assign malloc() result it.
Comments
Post a Comment