Ken H

Ken H

  • NA
  • 646
  • 354.6k

Using a recursive parameter problem

Jan 12 2014 8:50 AM
hello, 
   My questions are as follows:

#include <iostream>
using namespace std;

inline void print(char a,char b){
   cout<<a<<"->"<<b<<endl;
}

void test(int n,char c1,char c2,char c3){

   if(n==1) print(c1,c3);  // Here c3 is 'B'. Why is this so? c3 should be equal to 'C'.
   else{
      test(n-1,c1,c3,c2); // Note:Here c3 and c2 swapped positions.
      print(c1,c3);          // Here returned to normal.
   }
}
int main(){

    test(2,'A','B','C');

    return 1;
}
Its results are:
A->B
A->C
I think the result should be:
A->C
A->C


Thank.

Answers (1)