Date: Sun, 16 Aug 1998 11:58:45 +0300 (IDT) From: Eli Zaretskii To: Cephaler cc: djgpp AT delorie DOT com Subject: Re: yet more questions about pointers In-Reply-To: <01bdc7e8$c1ff0e20$4ac3b8cd@scully> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On 15 Aug 1998, Cephaler wrote: > This yielded 'raboof' to my delight... Now, have I found a good use for > pointers? Or is this bad bad code? It's one of the uses. I don't see anything particularly bad here, except that you never check the values returned by `malloc' (they might be NULL pointers if `malloc' fails to allocate), and you rely on "foobar" to be shorter than the size of the buffer allocated by `malloc'. > 2) Having not initialized string2 But you *did* initialize string2, by pointing it to the same address where string1 points. > a) do I have to free string2 and b) does > that have any effect on string1? (oops didn't free string1) You need to free any of them (but not both!). > 3) concerning strcpy...is there any special reason why I shouldn't just use > string1 = "foobar" ? THis is something else. It doesn't copy "foobar" at all, it changes the value stored in string1. After this, string1 points to the address where the constant string "foobar" is stored.