Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!bellcore!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: returning automatic variables Keywords: automatic variables, returning values Message-ID: <16257@smoke.brl.mil> Date: 24 May 91 21:11:35 GMT References: <1991May24.153133.13590@ux1.cso.uiuc.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 15 In article <1991May24.153133.13590@ux1.cso.uiuc.edu> nnj20229@uxa.cso.uiuc.edu (Nesha Nicole Jones) writes: >char *word(void) >{ > char name[100]; ... > return name; >} You're not returning the value of an auto variable, but rather a pointer to it. However, the auto variable "goes out of scope" (becomes invalid) upon return from the function; therefore what is pointed at by the returned pointer is no longer valid. There are several possible solutions, the simplest being to declare the name[] array as having static storage duration.