简体   繁体   中英

Understanding the logic behind a piece of C code

I would love if you guys could explain to me why the following piece of recursive code doesn't print the word 'test'. Thanks in advance.

void drawTetriminosEachPosition(int **tetriminos, char **dBoard, int **tBoard, int i){
  char c;
  char **dBoard2;

  if(tetriminos[i] == '\0')
  {
      return;
  }    
  else
  {
     dBoard2 = dBoard;
     DrawTetrimino(tBoard, tetriminos[i], dBoard, i+65);
  }
  i++;
  return (drawTetriminosEachPosition(tetriminos,dBoard,tBoard,i));

  ft_putstr("test");
  if(checkChar(tBoard,tetriminos[i]))
  {
      dBoard = dBoard2;
      return (drawTetriminosEachPosition(tetriminos,dBoard,tBoard,i));
  }     
}

Statements after a return are never executed. Since the first

return (drawTetriminosEachPosition(tetriminos,dBoard,tBoard,i));

does not depend on any condition, the following code is not executed.

When control reaches return ... it simply returns and next lines are not executed. Maybe you missed some logic in between?

As of now you can delete this part it doesn't matter

ft_putstr("test");
  if(checkChar(tBoard,tetriminos[i]))
  {
      dBoard = dBoard2;
      return (drawTetriminosEachPosition(tetriminos,dBoard,tBoard,i));
  }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM