Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ogicse!ucsd!hub.ucsb.edu!banana!tomkwong From: tomkwong@banana.ucsb.edu (Thomas K. Kwong) Newsgroups: comp.lang.c Subject: Re: Array question Message-ID: <9304@hub.ucsb.edu> Date: 21 Feb 91 18:53:03 GMT References: Sender: news@hub.ucsb.edu Reply-To: tomkwong@banana.UUCP (Thomas K. Kwong) Organization: University of California, Santa Barbara Lines: 34 In article rg2c+@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. If anybody >could briefly explain what exactly happens when you do this, I'd be >greatly abliged as at this point I'm mystified. An array subscript is really a shorthand of a pointer notation: a[i] is exactly the same as *(a+i) This conversion is done in compile time, so what you're doing is just using the space allocated in previous malloc() statement. -Thomas. ============================================================ * o | * -------------------- ----- |- * tomkwong@cs.ucsb.edu \/ | * 6600tom@ucsbuxa.edu -------- -- * -------------------- __ | * | | |-- * "Good work does not make a good |--| |-- * man, but a good man does good |--| |-- * work." | | |-- * -Martin Luther \| ------\ * * :-) :-) :-) :-) :-) :-) :-) :-) ============================================================