|
-
Jun 16th, 2001, 11:39 PM
#1
Thread Starter
Junior Member
not understanding pointers
I'm a complete newbie to C++, though I do know JavaScript, but I am clueless about understanding pointers. need some help please.
-
Jun 17th, 2001, 04:23 AM
#2
Monday Morning Lunatic
A pointer is a variable that contains a memory address. I'm assuming 32-bit now, because that's what you're most likely to be using (and 16-bit pointer methods really hurt).
When you use the & operator on a variable, you get its memory location:
Code:
int iNum; /* An integer variable */
int *ptr; /* A pointer to an integer variable */
Notice at the moment, ptr doesn't refer to a valid location, and will contain a totally arbitrary number from somewhere in your memory. So, you have to initialise it:Now, ptr contains the memory location of iNum, rather than iNum's value. You can get iNum's value out of this by using the * operator (indirection/dereferencing):
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 17th, 2001, 05:46 AM
#3
Frenzied Member
What parksie wrote is just the basics of pointers. Pointers are a much more complex topic. There are pointers to functions, structs etc. Sometimes they are not easy to understand. I suggest you to find a good tutorial on pointers, read it and practice of course
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|