> Thanks to everyone who offered answers to my question. It's starting to make
> sense now. Hope you don't mind if I dig a little further.
>
> If I understand correctly, char s1[]= "Hello"; puts that array of characters
> (plus the NULL) on the stack. Could I then execute something like
> printf("%s", s1) and have it print Hello? If true, when that printf runs,
> how does it know which bytes to pull off the stack. I might have added
> additional things to the stack, so how does it know where to find it if
> there is no pointer to it? If I could understand that, I'd really be getting
> somewhere. Thanks.
>
Whether it's on the stack or someplace else is immaterial - s1 is still
a pointer to a character string. The only distinction is that when declared
as an automatic, s1 points to someplace in the stack (as opposed to
someplace else in the dynamic heap) for the current function, and will be
valid only so long as it's in scope. Your stack is just another block on
the heap, so an address in the stack is just as valid as an address in
another block - the only difference is that when the stack frame is popped
off at the end of your function, references to s1 (say, if you'd passed the
pointer to another function) would no longer be valid.
--
Dan Rowley
Innovative Computer Solutions
Developers of fine software for Newton, Windows CE, Palm Computing Platform,
Windows, and MacOS