小编Max*_*itj的帖子

双指针vs指针数组(**数组vs*array [])

我不清楚这些之间的区别是什么2.我的教授写道**数组与*array []相同,我们得到了一个例子,他使用了**数组(所以在类之后我尝试用*array交换它] ]它没有用),谁能告诉我这些2是否与他写的一样?无论如何,这个类是关于动态内存分配的

@一旦我改变了双指针,这一行开始抛出错误

    lines = malloc(sizeof(char*));
Run Code Online (Sandbox Code Playgroud)

以及其他一些内存重新分配的地方

@ 2地狱耶,这是整个代码

对于那些评论吼叫,因为他的陈述是,因为[]内部没有任何内容

    **array = *array[]
Run Code Online (Sandbox Code Playgroud)

大新闻

对于给您带来的任何不便,我感到非常抱歉,在写这篇文章的时候我太累了,这里是整个代码,没有编辑

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char **lines;     // global text buffer, organized as an array of lines

    // --------------------------------------------------------------------------------
    // initialize global buffer
    void initialize()
    {
      lines = malloc(sizeof(char*));
      lines[0] = NULL;
    }

    // --------------------------------------------------------------------------------
    // return number of lines in buffer
    int countLines()
    {
      int count = 0;
      while(lines[count++]) ;
      return count-1;
    }

    // --------------------------------------------------------------------------------
    // print one line
    void printLine(int line) …
Run Code Online (Sandbox Code Playgroud)

c pointers multidimensional-array dynamic-memory-allocation

12
推荐指数
2
解决办法
2万
查看次数

为什么递归函数的输出为0?

有人可以解释一下为什么这段代码返回0?

#include <stdio.h>
int factorial(int input)
{
    if (input > 0)
    {
        input--;
        return input * factorial(input);
    }
    return 1;
}
int main()
{
    printf("%d", factorial(20));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c recursion

-2
推荐指数
1
解决办法
54
查看次数