Yes, I read this question and answers: Passing an array by reference in C? . I have a similar problem and implemented the same idea from this question.
However, I still get the error message from the following code:
#include <iostream>
void FillArray(int** myArray)
{
free( *myArray ) ;
* myArray = (int*) malloc(sizeof(int) * 2);
*myArray[0] = 1;
*myArray[1] = 2;
}
int main()
{
int* myArray = NULL;
FillArray(& myArray);
return 0;
}
I got the following runtime error right after the completion of the FillArray function:
Unhandled exception at 0x773115de in Program.exe 0xC00000005: location of access violation record 0xcccccccccc.
Visual Studio, Visual ++ Empty Project. main.cpp. , ++ C? , , C? main.cpp main.c, . ( , "pass by reference" , C ++.)
.
,
.