delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/14/21:15:22

From: "Cephaler" <cephaler AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: yet more questions about pointers
Date: 15 Aug 1998 01:05:45 GMT
Organization: ICGNetcom
Lines: 35
Message-ID: <01bdc7e8$c1ff0e20$4ac3b8cd@scully>
NNTP-Posting-Host: wbg-va2-10.ix.netcom.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

  Ok just concluded several tests concerning pointers, now I have some
questions to verify my results:

1) A simple test program:
int main(void) {
  char *string1=(char *)malloc(80);
  char *string2;

  strcpy(string1,"foobar");

  string2 = string1;

  strcpy(string2,"raboof");

  printf("%s\n",string1);
  return(0);
}

This yielded 'raboof' to my delight... Now, have I found a good use for
pointers? Or is this bad bad code?

2) Having not initialized string2, a) do I have to free string2 and b) does
that have any effect on string1? (oops didn't free string1)

3) concerning strcpy...is there any special reason why I shouldn't just use
string1 = "foobar" ?

If the answers to these questions are what I think they are my pointer
dilemmas are over... (game still crashes though :( )

- Cephaler -

p.s. thanks! <-- insert in previous messages as well


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019