Help Tracing through code
Hey guys, I'm currently in a Summer class dealing with C Programming and I'd like some help tracing through this code so I understand how it works exactly. Any help would be greatly appreciated!
Code:
#include <stdio.h>
void flipper(int,char *);
int main(void){
char path[5] ;
path[4]=0;
flipper(0,path);
system("pause");
return 0;
}
void flipper(int level, char* path){
*(path+level)='A'; /* coin flip side A */
if(level==3) /* flipped coin 4 report results */
printf("%s\n",path);
else
flipper(level+1,path); /* flip next coin */
*(path+level)='B'; /* coin flip side 'B' */
if(level==3) /* flipped four coins if you want to change the number of coin tosses shange the 3 to something else both here and above*/
printf("%s\n",path); /* report the path */
else
flipper(level+1,path); /* not done flip next coin */
return;
}
This is supposed to give the possible permutations for flipping a coin. I'm a bit confused on a few things done here.
Like... what exactly the char path[5]; is, path[4] i believe would be to say there are 4 flips. Then I'm also confused about the * (path+level) part and the if statements. Thanks again! :)