title: Manipulating char arrays using pointers in c
body: <p>So I tried this code </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(void)
   {
          char string[] = "hello world";
          char *my_ptr = string;
          *my_ptr='Y';
          printf("the first char of string is %c", *my_ptr);
   }
  </code></pre>
  
  <p><strong>OUTPUT_1 :-</strong></p>
  
  <pre><code>the first char of string is Y
  </code></pre>
  
  <p>Now if I want to print the complete scentence in the string ("Yello world"). For that I changed 7th line to :-</p>
  
  <pre><code>printf("the whole string is %s", *my_ptr);
  </code></pre>
  
  <p><strong>OUTPUT_2:-</strong></p>
  
  <pre><code>Segmentation fault (core dumped)
  </code></pre>
  
  <p>But if I try changing it to this :-</p>
  
  <pre><code>printf("the whole string is %s", my_ptr);
  </code></pre>
  
  <p><strong>OUTPUT_3 :-</strong></p>
  
  <pre><code>the whole string is Yello world
  </code></pre>
  
  <ol>
  <li><p>Could someone please explain me why are the second case is failing ? AND </p></li>
  <li><p>Why the third case prints correct ?</p></li>
  </ol>
  
  <p>From my understanding *my_ptr (as well as my_ptr both) have the address of the first location, so why does the first one fail in printing a complete string , whereas the second one does well. Im a beginner so it would help if you could detail the reason behind such a behaviour in these cases.</p>