title: What occurrs in a 'for loop' at the hardware level? Is memory automatically assigned? (C++)
body: <p>I have some code here which reverses an array of characters:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  char s[50];
  
  void reverseChar(char * s)
  {
      for (int i=0; i&lt;strlen(s)/2; ++i)
      {
          char temp = s[i];
          s[i] = s[strlen(s)-i-1];
          s[strlen(s)-i-1] = temp;
      }
  }
  
  int main() {
      cout &lt;&lt; "Hello, this program reverses words." &lt;&lt; endl &lt;&lt; endl;
      cout &lt;&lt; "Enter in a word, no spaces please:" &lt;&lt; endl;
      cin.getline(s, 50);
      cout &lt;&lt; "This is the word, it has now been reversed:" &lt;&lt; endl;
      reverseChar(s);
      cout &lt;&lt; s;
      return 0;
  }
  </code></pre>
  
  <p>In the for loop can someone explain what is going on at the hardware level. I understand 'temp' is allocated to a byte, which is assigned to the value of s[i].</p>
  
  <p>Is memory allocated to everything?</p>
  
  <p>The equals sign, s[i], etc?</p>
  
  <p>After the byte is assigned to the value in s[i], s[i] is assigned to some other value in array s. This other value is then assigned to temp.</p>
  
  <p>I'm having trouble understanding where all these bytes are going, and how they are being manipulated by C++.</p>
  
  <p>I understand that in the line:</p>
  
  <pre><code>s[i] = s[strlen(s)-i-1];
  </code></pre>
  
  <p>The placeholder values are being swapped?</p>
  
  <p>In this line:</p>
  
  <pre><code>s[strlen(s)-i-1] = temp;
  </code></pre>
  
  <p>The 'copied' value is sent to 'temp'. But what happens to this temp value afterwards, does it become the new 'temp' once the for loop reiterates?</p>