SL> only have 5 bytes (plus
DM> the nul) = 6. ;-)
SL> printf("Enter a number: ");
SL> scanf("%s", sTemp);
AM> NULL pointer!!!!! Causes lot's of run-time errors.
AM> You must allocate the
AM> memory before using it.
DM> Nope NOT NULL pointer!!!! _RANDOM_ pointer. :-)
SL> Wait a second? Is this PSEUDOrandom or is it TRULY random?
SL> There could be interesting implications...
Literally, it is merely whatever was in that memory location before it
"became" a char*.
For example, if a char* is 2 bytes (which it often is on 16-bit small memory
models), and if the function is:
void foo()
{
char* sTemp;
}
(i.e., only one variable), and the stack pointer is:
---> direction of stack growth
12 34 56 78 9a bc de f0
^^
Then, sTemp will have 0x789a (or, on x86 systems, 0x9a78) as its pointer.
Whatever happened to be at this address is what it's pointing at.
Next time you call foo, if nothing else was called, it will _likely_ have the
same value as it left with. However, there is nothing to guarantee this -
the compiler is free to (but rarely does, except for a few debugging
libraries) put more garbage into the stack area that isn't "owned" by your
program.
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|