Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 正在尝试递归打印数组元素_C_Arrays_Printf - Fatal编程技术网

C 正在尝试递归打印数组元素

C 正在尝试递归打印数组元素,c,arrays,printf,C,Arrays,Printf,您应该打印数组项,而不是函数的返回值,请使用以下代码 $ ./a.out 5 0 1 1 0 你没有返回任何东西,那么第二个printf应该打印什么?我还没有做指针,但是如果我只是用我最初写的替换*a,a[]。不管怎样,它还是有效的! $ ./a.out 5 0 1 1 0 int printArray(int *a, unsigned int n){ if (n == 4){ printf("%d", a[4]); } else {

您应该打印数组项,而不是函数的返回值,请使用以下代码

$ ./a.out 
5
0
1
1
0

你没有返回任何东西,那么第二个printf应该打印什么?我还没有做指针,但是如果我只是用我最初写的替换*a,a[]。不管怎样,它还是有效的!
$ ./a.out 
5
0
1
1
0
int printArray(int *a, unsigned int n){
    if (n == 4){
        printf("%d", a[4]);
    }
    else {
        printf("%d", a[n]);
        printArray(a,n+1);
    }
}