title: Quadruple pointer and memcpy() in C
body: <p>First of all, I know triple and quadruple pointers are bad practice and are ugly, that's not the point of this question, I'm trying to understand how they work. I'm aware using a struct would be much better.</p>
  
  <p>I am trying to write a function that does some memory operations using <code>memmove()</code> and <code>memcpy()</code> on triple and double pointers that are passed-by-reference (or the C version of that). My <code>memmove()</code> works fine, but the <code>memcpy()</code> yields a <code>SIGSEGV</code>. Here's a minimal example</p>
  
  <pre><code>#include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  #define UNDO_DEPTH 25
  
  
  void boardSave(int ***board, int game_sz, int ****history) {
      // Shift history to the right
      memmove(*history + 1, *history, (UNDO_DEPTH - 1) * sizeof(**history));
      // Copy board into history
      for (int row = 0; row &lt; game_sz; ++row) {
          memcpy((*history)[0][row], (*board)[row], game_sz * sizeof((**board)[row]));
      }
  }
  
  int main(){
      // Game
      int game_sz = 5;
      // Allocate array for the board
      int **board = calloc(game_sz, sizeof(int *));
      for (int i = 0; i &lt; game_sz; ++i) board[i] = calloc(game_sz, sizeof(int));
      // Allocate array for the history
      int ***history = calloc(UNDO_DEPTH, sizeof(int **));
      for (int i = 0; i &lt; UNDO_DEPTH; ++i) {
          history[i] = calloc(game_sz, sizeof(int *));
          for (int j = 0; j &lt; game_sz; ++j) {
              history[i][j] = calloc(game_sz, sizeof(int));
          }
      }
      board[0][0] = 1;
      boardSave(&amp;board, game_sz, &amp;history);
  }
  </code></pre>
  
  <p>The objective of <code>boardSave()</code> here is to copy <code>board</code> onto <code>history[0]</code>. What am I doing wrong? Why is this causing a segmentation fault?</p>