I am trying to make a recursive function to print the content of an array. The main looks like this:
#include <stdio.h>
static int s_index;
int main(void) { int even[] = {2, 4, 6, 8}; s_index = 0; print(even);}
The print function looks like this:
void print(int * array) {
if(s_index > 3) {
printf("\n"); return;
}
printf(" %d ", *array); ++s_index; print(array + s_index);
}
What I notice is:
if &even is 0x7fffffffdbf0 then (array + s_index) increments as follow with s_index:
s_index = 0 : 0x7fffffffdbf0;
s_index = 1 : 0x7fffffffdbf4;
s_index = 2 : 0x7fffffffdbfc;
it should be 0x7fffffffdbf8!!?
It is blowing my mind, could someone help with that? Thank you for your answers.
*array-->*(array+s_index)andprint(array + s_index);-->print(array);print(array + 1)