title: C string reversal using recursive function
body: <p>Hi I came across this piece of code in Youtube when I was searching for a simple string reversal in C. It uses function recursion to print chars from the end to start of the string.</p>
  <p>However, I am confused as to how this syntax works when it reaches the null terminator.</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
      char a[100];
      scanf(&quot;%[^\n]s&quot;, a);
      reverse(a);
      return 0;
  }
  
  void reverse(char* a){
      
      if(*a){
          reverse(a+1);
          printf(&quot;%c&quot;, *a);
      }
  }
  </code></pre>
  <p>Assume that we have the input &quot;HELLO&quot;</p>
  <p>What I understand is when recursion is happening, the final if statement continues to the last letter until it stops at the \0 which will make the if statement false, and only then will it start to print the character.</p>
  <pre><code> printf(&quot;%c&quot;, *a);
  </code></pre>
  <p>which would print the letter &quot;O&quot; just after returns from the call to reverse(\0)</p>
  <p>Now, after char 'O' has been printed, it will return again to the function which has *a = L, now.. what I'm understanding is it will keep going back and forth characters O and L.</p>
  <p>What am I missing here?</p>