Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!njin!njitgw!yxz1684@hertz.njit.edu From: yxz1684@hertz.njit.edu (Ying Zhu ee) Newsgroups: comp.lang.c Subject: Question about pointer Message-ID: <2488@njitgw.njit.edu> Date: 1 Mar 91 15:46:59 GMT Sender: news@njitgw.njit.edu Distribution: usa Organization: New Jersey Institute of Technology, Newark, N.J. Lines: 34 The following is a small program from "Mastering C pointers" by Robert J. Traister. I am confusing with the pointer here. Since the r[100] is an automatic variable, after calling the "combine" the r[100] will be deallocated. Then the p will point to an unsafe place. Actually, runing this program on VAXII/GPX(ULTRIX) and Sparc( BSD UNIX ) here have different answers. Any one familiar with C can help me? Thank you! main() { char a[10], b[10], *p, *combine(); strcpy( a, "horse" ); strcpy( b, "fly" ); p=combine(a, b); printf("%s\n", p ); } char *combine(s,t) char *s, *t; { int x,y; char r[100]; strcpy(r,s); y=strlen(r); for ( x=y; *t != '\0'; ++x ) r[x] = *t++; r[x]='\0'; return(r); }