Xref: news2.mv.net comp.os.msdos.djgpp:5014 From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Question about pointers Date: Fri, 14 Jun 1996 23:23:24 -0700 Organization: Alcyone Systems Lines: 40 Message-ID: <31C256DC.2F876346@alcyone.com> References: <4phibg$sek AT usenet DOT rpi DOT edu> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp David J. Calvin wrote: > Here's what I'd like to know: > > 1) Obviously the first line, big zero, will allocate 40k of memory > to store itself in. But what about big *one, etc? Do they also > take up 40k of memory, or just enough space to hold an address? You're confused about the difference between accessing something by value or by reference. A pointer is a reference. In the code int i = 2, *pi = &i; i is declared as a variable of type int, and pi is declared as a pointer to int, which points to i. Change i, you change *pi. Change *pi, you change i. They reference the same object. > 2) In the one=two=three=&zero line, do the pointers now take up 40k > of memory each, or just enough to hold an address? No. The pointers are merely, well, pointers to data somewhere else. Their declaration does not imply the allocation of any memory other than the automatic stack allocation of enough space to hold the size of the pointer. > What I really need to know is if you can make many pointers pointing > to one variable and save memory that way. Thanks in advance. That's one reason to use them, yes. But keep in mind that they all reference the same object, namely the 40k array. If you dereference the pointers to change the data, or you change the data through the array, the data is being changed, and all of the pointers will reflect that change during use, since they're all referencing the same data. (I wonder if I could have made that sentence more redundant.) -- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_