我无法理解如何为双指针分配内存.我想读取一个字符串数组并存储它.
char **ptr;
fp = fopen("file.txt","r");
ptr = (char**)malloc(sizeof(char*)*50);
for(int i=0; i<20; i++)
{
ptr[i] = (char*)malloc(sizeof(char)*50);
fgets(ptr[i],50,fp);
}
Run Code Online (Sandbox Code Playgroud)
而不是这个我只是分配一个大的内存块并存储字符串
char **ptr;
ptr = (char**)malloc(sizeof(char)*50*50);
Run Code Online (Sandbox Code Playgroud)
那会错吗?如果是这样,为什么呢?
如果函数在同时定义变量时调用自身会导致堆栈溢出吗?gcc中是否有任何选项可以重用相同的堆栈.
void funcnew(void)
{
int a=10;
int b=20;
funcnew();
return ;
}
Run Code Online (Sandbox Code Playgroud)
函数可以重用它之前使用的堆栈帧吗?gcc中的选项是什么在尾递归中重用相同的帧?