|
int fun (unsigned char * in, unsigned char *&out)
{
int size;
for (...) ... determine the length of In
out = new unsigned char [size]; // allocate new space, pay attention to the out pointer to pass by reference,
----------------------------------- // To change the pointer outside you
return size; // Return length
}
Arrays of indefinite length, that is, dynamically allocated memory areas, can be pointed to by pointers.
Indefinite length is not to know the length, you know the length when you allocate, but the calling party does not know the length.
Length, then just pass this length out. |
|