title: Printing all possible combinations of elements in an array
body: <p>During recursion, once elements are changed in an array, this change persist. How to pass array so that changes are done according to the call stack ?
  Once element at index 2 is set, its set in every function call.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  void recur(int flag[], int n, int idx){
      if(idx==n){
          for(int i=0; i&lt;n; i++)
              if(flag[i])
                  printf("%d  ", i);
          printf("\n");
          return;
      }
  
      recur(flag, n, idx+1);
      flag[idx] = 1;
      recur(flag, n, idx+1);
  }
  int main(){
      int flag[] = {0, 0, 0};
      recur(flag, 3, 0);
      return 0;
  }
  </code></pre>
  
  <p>It gives me the following output:</p>
  
  <pre><code>2
  1 2
  1 2
  0 1 2
  0 1 2
  0 1 2
  0 1 2
  </code></pre>