title: How to swap 2 strings passed as pointers in a function?
body: <p>I have to swap 2 char strings that I passed as pointers into a function:
  bool swap_strings (char* string1, char* string2)
  if both strings have not same length return false, else if swapping worked, return true;</p>
  
  <p>how can I realise this? why is this not correct :</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  
  bool swap_strings(char * string1, char * string2) { 
      char * s;
      char * s2;
      char * tmp = nullptr;
          for (s = string1; *s != '\0'; ++s);
          for (s2 = string2; *s2 != '\0'; ++s2);
          if ((s - s2)  != 0) {
              return false;
          }
          else {      
              tmp = *&amp;string1;
              string1 = *&amp;string2;
              string2 = *&amp;tmp;
              cout &lt;&lt; tmp &lt;&lt; string1 &lt;&lt; string2&lt;&lt; endl;
          }
  
          return true;
      }
  
  
  
  int main()
  {
  
      bool da = false;
      char s1[] = "hallo1";
      char s2[] = "ababab";
  
      da = swap_strings(s1, s2); 
  
      cout &lt;&lt; da &lt;&lt; s1 &lt;&lt; s2 &lt;&lt;endl;
  }   
  </code></pre>