Scoping question in C

Henry Spencer henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org
Thu Jun 9 23:14:39 UTC 2005


On Thu, 9 Jun 2005, William Park wrote:
> 	x = "something";
> 	return (1);
> where 'x' is global variable being used elsewhere.  Can I use 'x' after
> func() exits?  That is, is 'x' still pointing to string "something"?

Yes.  This isn't about *scope*, which is where things are visible, but
about storage duration, which is how long things live.  String constants
have static storage duration -- they last the lifetime of the program.

                                                          Henry Spencer
                                                       henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list