I want to declare an array that is stored in a pointer A. I have the following code.
int length = 8;
int *A;
A = (int*) malloc(length*sizeof(int));
A = {5, 1, 3, 5, 5, 2, 9, 8};
However, the array cannot be initialized like above. The error says "cannot convert to 'int' in assignment". How do I fix this issue?
Additionally, are malloc and memset necessary in c++ when declaring an array (for a pointer)?
Thanks!
std::vector.std::vector<int> A{5, 1, ..., 8};