boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

018-ptr-recursion.c (421B)


      1 /* tests/cc-e2e/18-ptr-recursion.c — pointer-arith + recursion + global-array decay.
      2  * Split from 01-kitchen-sink. */
      3 
      4 int g_arr[3] = { 10, 20, 30 };
      5 
      6 int sum_arr(int *p, int n) {
      7     if (n == 0) return 0;
      8     return *p + sum_arr(p + 1, n - 1);
      9 }
     10 
     11 int test_ptr_recursion(void) { return sum_arr(g_arr, 3); }      /* 60 */
     12 
     13 int main(int argc, char **argv) {
     14     if (test_ptr_recursion() != 60) return 1;
     15     return 0;
     16 }