Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!sun-barr!ccut!kogwy!new1!roger From: roger@zuken.co.jp (Roger Meunier) Newsgroups: comp.lang.c Subject: Re: ## question on memory allocation for char strings ## Message-ID: Date: 29 Jun 90 13:51:24 GMT References: <601@babcock.cerc.wvu.wvnet.edu> Sender: news@new1.zuken.co.jp Organization: ZUKEN Inc. Yokohama, JAPAN Lines: 17 In-reply-to: siping@cathedral.cerc.wvu.wvnet.edu's message of 28 Jun 90 17:49:18 GMT In article <601@babcock.cerc.wvu.wvnet.edu> siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) writes: >char *f2() >{ > char abc[100]; > > strcpy(abc, "12345"); > > return(abc); >} If you want to use the return value from f2() safely, make abc storage class static, not automatic. No variable in f2()'s scope is safe outside of f2() otherwise. -- Roger Meunier @ Zuken, Inc. Yokohama, Japan (roger@zuken.co.jp)