So here i am struggling with this program, i was trying to find out how can I use a array of pointers declared into main, in a recursive function to memorize data, the question that arises here is if it's the same approach as for a single pointer, what about for a struct type ? what is the best way to pass by reference a variable/array to a recursive function ?
#include <stdio.h> #include <stdlib.h> #define N 1 void f(int i,int j,int *cnt); int j=0; int main(int argc, char *argv[]) { int *cnt=0; f(0,++j,&cnt); printf("------ %d ---- \n",cnt); system("PAUSE"); return 0; } void f(int i,int j,int *cnt){ if(i>N){ printf("---if --- %d ---- %d \n",i,j); (*cnt)++; return; } (*cnt)++; printf("---bg --- %d ---- %d \n",i,j); f(i+1,++j,cnt); f(i+1,++j,cnt); } Another thing i'd like to know is how does the recursive functions handle the ++i and i++ and i+1 increments (when passed as parameters),
cntto point at any memory.