Array question
Henry Spencer
henry at zoo.toronto.edu
Sun Feb 10 16:06:42 AEST 1991
In article <EbhAAgG00WBNM2PIt_ at andrew.cmu.edu> rg2c+ at andrew.cmu.edu (Robert Nelson Gasch) writes:
>What happens if I do the following? Basically I don't really understand
>*why* this works:
>
> int *this_ptr;
> this_ptr [0] = 1;
> this_ptr [1] = 2;
> . . .
> this_ptr [9] = 10;
>
>This works fine, but I really don't know why?? It seems you're using
>memory to store an array which was never really allocated...
Precisely correct. What is happening is that on your machine, whatever
value this_ptr happens to get as its initial value happens to point to
some memory that you are allowed to write on. You're scribbling on a
random piece of memory, and random things could happen as a result.
Well-designed machines try to make this a catastrophic error.
--
"Read the OSI protocol specifications? | Henry Spencer @ U of Toronto Zoology
I can't even *lift* them!" | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list