Raise questions:
When writing a program, sometimes only one pointer variable is defined in the main program, and a dynamic array pointed to by this variable is created in the subroutine and assigned a value. In this case, you only need to ensure that the real parameters and form parameters point to the same address.
Routine:
Main Program:
Main Program:
Main ()
{
Char * PCH;
Creatdynarray (& PCH );
}
Subroutine:
Void creatdynarray (char ** inputpointer)
{
* Inputpointer = new char [10];
// Dynamically generate accepted strings
For (INT I = 0; I <10; I ++)
{
* Inputpointer [I] = 'a ';
}
}
However, the following method is not feasible:
The inverse example is as follows:
Main Program:
Main ()
{
Char * PCH;
Creatdynarray (PCH );
}
Subroutine:
Void creatdynarray (char * inputpointer)
{
Inputpointer = new char [10];
// Dynamically generate accepted strings
For (INT I = 0; I <10; I ++)
{
Inputpointer [I] = 'a ';
}
}
In this method, the real parameter PCH and the form parameter inputpointer point to different addresses, so the real parameter does not point to the dynamic space opened by the form parameter,