very basic c++: seg fault when doing cross class pointer assignment with malloc
<p>In the following code, 'buf' is malloced, but then why accessing its member gives seg fault?</p>

<p><strong>edit</strong>: thanks to cnicutar and David, I understand the problem now.</p>

<pre><code>class tool{
   ...
   void do(char* buf){
        buf = malloc(100);
        ... //init buf[0], buf[1], etc
   }
};

class user{
   ...
   tool  *tl;
   char  *buf;

   user(){

       tl = new tool;
       tl -&gt; do(buf);

       cout&lt;&lt;buf[1]&lt;&lt;endl;  //---&gt; gives seg fault!  Why?
   }
};
</code></pre>
