On Tuesday 22 November 2005 14:31, [EMAIL PROTECTED] wrote:
> >Ummmm ...
> >
> >Coding 3.
> >#include <stdio.h>
> >#include <stdlib.h>
> >#include <string.h>
> >char *
> >somefunction()
> >{
> > char *string2 = "some words";
> > return string2;
> >}
> >int main (void)
> >{
> > char *string;
> > string = somefunction();
> > printf ("\n\nString is: %s\n\n", string);
> > return 0;
> >}
> >
> >somefunction returns string2 which is trash!
> >formally: The scope of string2 does not extend to main!
> >(even if it works, and it might, it's WRONG)
> >
> >
>
> What are you talking about ?
>
> Tell me why it is trash.
"some words" is not a global variable in somefunction().
There is no rule to say that the storage used for "some words" shall be intact
after somefunction() returns. It might be, and your example might work, but
it's still illegal.
James
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html