Consider the following functions
void alloco(int **ppa)
{
int i;
printf("inside alloco %d\n",ppa); /*this function allocates and fills 20 * sizeof(int) bytes */
*ppa = (int *)malloc(20 * sizeof(int));
/*fill all 20 * sizeof(int) bytes */
}
int main()
{
int *app = NULL;
int i;
printf("inside main\n");
alloco(&app);
for(i=0;i<20;i++) /*ISSUE::how will i know to traverse only 20 indexes?*/
printf("app[%d] = %d \n", i, app[i]);
return(0);
}
基本的に、main() はどのようにしてトラバースするバイト数、つまり alloco() 関数によって割り当てられたメモリを知るようになるのでしょうか。文字配列に NULL のような区切り文字はありますか?