title: String reverse using pointers
body: <p>I'm trying to reverse a string using pointers.When i try to print the reversed string instead of getting DCBA i'm getting out only as BA?Can anyone help me on this?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  void reverse(char *);
  void main()
  {
    char str[5] = "ABCD";
    reverse(str);
  }
  
  void reverse(char *str)
  {
    char *rev_str = str;
    char temp;
    while(*str)
        str++;
    --str;
  
    while(rev_str &lt; str)
    {
        temp = *rev_str;
        *rev_str = *str;
        *str = temp;   
        rev_str++;      
        str--;
    }
    printf("reversed string is %s",str);
  }
  </code></pre>