title: Looping through a char array in C
body: <p>I am not a C developer or know much about C but I came across this C interview question: </p>
  
  <pre><code>int toto(char *a, char *b){
      while(*a++ == *b++);
      return(*a == 0 &amp;&amp; *b == 0);
  }
  </code></pre>
  
  <p>I spent a good amount of time trying to figure it out and after reading a few things online I kind of grasped what it is trying to do but there are still some weird behaviours that arise. 
  From what I understand (please correct me if I'm wrong), this piece of code will go through two strings (char arrays) and determine whether they are equal up until the last character and returns true only if the last character is different. <code>return (*a == 0 &amp;&amp; *b == 0)</code> checks for the <code>0</code> integer that all strings end with in <code>C</code>. This only happens after the loop has exited i.e when two characters aren't equal before the increment happens; so if the last two characters are not equal, it will increment them to the <code>0</code> int and go through to the return statement. I also noticed that that if the strings differ by 1 then it still returns true if the strings are equal up until <code>n-1</code> for example: </p>
  
  <pre><code>char a[] = "ggr"
  char b[] = "ggre"
  //returns 1
  char a[] = "ggr"
  char b[] = "ggf"
  //returns 1
  </code></pre>
  
  <p>I found this behaviour peculiar but the test case that I can't understand is the following: </p>
  
  <pre><code>char a[] = "abcd";
  char b[] = "abcd";
  //returns 1
  char a[] = "abc"
  char b[] = "abc"
  //returns 0
  </code></pre>
  
  <p>I understand why <code>abc</code> returns false but I have no idea why it wouldn't return the same for <code>abcd</code>. To me, it seems like it treats strings of different lengths differently but the code doesn't seem to care about the length. </p>
  
  <p>Can anyone explain what the code intends to do and why the code behaves differently when given different lengths of strings. I have a feeling it has to do with the order of precedence for certain operators but I couldn't find an answer.</p>
  
  <p>Edit: It seems the code supplied by the interview is buggy on purpose, I was under the impression that the code is valid.</p>