Array question
Xiang-Min Wang
xwang at gmuvax2.gmu.edu
Sat Mar 2 15:49:51 AEST 1991
In article <9304 at hub.ucsb.edu> tomkwong at banana.UUCP (Thomas K. Kwong) writes:
>In article <EbhAAgG00WBNM2PIt_ at andrew.cmu.edu> rg2c+ at andrew.cmu.edu (Robert Nelson Gasch) writes:
>>
>> 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.
Please notice that althouhg the pointer 'this_ptr', after declared, is
not initialized by YOU (I am not sure the C compiler will initialize
it to zero or not), it bears some value (as an address) ANYWAY.
Therefore, you can do the "normal" things to it like the assignment:
this_ptr[i] = i (or *(this_ptr+i) = i )
Simply speaking, your program is SYNTACTICALLY correct, but FUNCTIONALLY
wrong.
xwang
internet: xwang at gmuvax2.gmu.edu
bitnet: xwang at gmuvax.gmu.edu
More information about the Comp.lang.c
mailing list