Array question

uunet!bria!mike uunet!bria!mike
Mon Feb 11 07:53:53 AEST 1991


In an article, andrew.cmu.edu!rg2c+ (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;

You are writing to some random memory location, and the reaction varies
dependant on the operating system and/or hardware.

One thing to point out is that pointers and arrays are _not_ interchangable
entities _except_ when you are passing them to functions.  The moral is this:
when you mean to use a pointer, use a pointer; when you mean to use an array,
use an array.

-- 
Michael Stefanik                       | Opinions stated are not even my own.
Systems Engineer, Briareus Corporation | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly
found to be saying things like "Well, it works on my DOS machine ..."



More information about the Comp.lang.c mailing list