小编cha*_*tay的帖子

我无法理解这个程序是做什么的,它是一个递归的程序

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define SIZE 10 

int whatIsThis(const int b[], size_t p);

int main(void) {
    int x;
    int a[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

    x = whatIsThis(a, SIZE);

    printf("result is %d\n", x);

    _sleep(1000 * 100);
}

int whatIsThis(const int b[], size_t p) {
    if (1 == p) {
        return b[0];
    } else {
        return b[p - 1] + whatIsThis(b, p - 1);
    }
}
Run Code Online (Sandbox Code Playgroud)

很抱歉问这个问题,但我几乎是C编程的初学者,我无法理解这个程序的逻辑,特别是return b[p-1]+ …

c arrays recursion function

3
推荐指数
1
解决办法
191
查看次数

标签 统计

arrays ×1

c ×1

function ×1

recursion ×1