From: firewind Newsgroups: comp.os.msdos.djgpp Subject: Re: Please help the newbie! Date: 25 Sep 1997 04:34:47 GMT Organization: Netcom Lines: 57 Message-ID: <60cpl7$2pk@sjx-ixn3.ix.netcom.com> References: <875153762 DOT 25454 AT dejanews DOT com> NNTP-Posting-Host: elp-tx1-11.ix.netcom.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk joe DOT charles AT sprintranet DOT com wrote: > I'm teaching myself C++ on a Toshiba Tecra running Win95. I've been using > DJGPP v2 and RHIDE with no problems until now... Day 8 of "Teach Yourself > C++ in 21 Days." 21 days? To learn C++? Surely this is a joke. I'd say, if you must continue using this book, try going at a slower pace, and reading extra material on the side. > Day 8 discusses pointers, and says you can use the "&" operator to see the > particular address of any given variable, as in: > int temp=5; > cout << "Address: " << &temp > Now, when I compile this and run it, I get "Address: 1" instead of the > actual memory address of the temp variable. If the method above is the only way you know to show the address of a variable, how do you know the output is wrong? Were you expecting to see '5'? If you were, you apparently don't understand the underlying concept, and I'd recommend rereading your material more carefully. If, on the other hand, '1' simply doesn't seem 'right' for the address of temp, remember a few things: * 1 could be the correct address; temp might be the first object in its particular segment. * Pointer representation, whether it be via 'printf("%p", &foo)' or by 'cout << &foo' -does not have to mean anything.- All ANSI\ISO requires is that each individual compiler is consistent in its pointer output; it does not have to be correct or make sense. * Trying to show a pointer is pretty worthless, anyway. > Does DJGPP not support the & operator? How can I see the address of a > given variable? & works fine in DJGPP. It is important to remember that you -never- need to know the address of a particular address specifically to use pointers. For example: int foo = 99; int *bar = &foo; Saying '*bar = 12' is now the same as saying 'foo = 12'. The compiler takes care of knowing addresses for you; you never need to touch the icky things. My personal advice? Drive down to good ol' Barnes and Nobles and pick up a copy of "The C Programming Language," by Dennis Ritchie and Brian Kernighan. It is -essential- to master C before moving on to object-oriented C++. C++ I learned from a mish-mash of places; can anyone recommend a single, good book for C++? -- [- firewind -] [- email: firewind AT metroid DOT dyn DOT ml DOT org (home), firewind AT aurdev DOT com (work) -] [- "You're just jealous because the voices talk to -me-." -]