i don't understand pointers ????????????????????????
how can I learn about pointers?
Page 1 of 16 Replies - 490 Views - Last Post: 25 December 2009 - 12:29 PM
Replies To: how can I learn about pointers?
#2
Re: how can I learn about pointers?
Posted 23 December 2009 - 11:04 PM
#3
Re: how can I learn about pointers?
Posted 23 December 2009 - 11:17 PM
Definitely read up on them, but do you have any specific question about them? As a very rough intro to pointers, think of them like this. They point to an object in memory. As opposed to actually storing the data, they store a copy of the address of the data. It's like opening your mailbox and instead of finding your package you found a note that told you where to get it. That being said, here's how to define them.
int * a; this instantiates a pointer to an int
so...
cout << a; would produce something like this ffa4ad56. basically a hex number
however, when you want to access the actual data being pointed to, you must "de-reference" the pointer.
like this.
cout << *a; that would produce the actual value of the int such as "4"
If you want to assign something be careful. Remember to de-reference or else you will change the value of the address in memory and bad things will happen.
so again if you want to change the value, do this.
*a = 10 and so on.
Hope this gets you started!
int * a; this instantiates a pointer to an int
so...
cout << a; would produce something like this ffa4ad56. basically a hex number
however, when you want to access the actual data being pointed to, you must "de-reference" the pointer.
like this.
cout << *a; that would produce the actual value of the int such as "4"
If you want to assign something be careful. Remember to de-reference or else you will change the value of the address in memory and bad things will happen.
so again if you want to change the value, do this.
*a = 10 and so on.
Hope this gets you started!
#4
Re: how can I learn about pointers?
Posted 24 December 2009 - 01:30 PM
Those links helped me a lot when I was learning pointers in C.
Pointer Basics - http://cslibrary.stanford.edu/106/
Pointer and Memory - http://cslibrary.stanford.edu/102/
Arenīt function pointers a little too much for a newbie.?
Pointer Basics - http://cslibrary.stanford.edu/106/
Pointer and Memory - http://cslibrary.stanford.edu/102/
janotte, on 23 Dec, 2009 - 10:04 PM, said:
Arenīt function pointers a little too much for a newbie.?
This post has been edited by Neeskens: 24 December 2009 - 01:31 PM
#5
Re: how can I learn about pointers?
Posted 24 December 2009 - 04:42 PM
A few more excellent pointer links:
http://www.daweidesi...in/pointers.php
http://www.eternally...t_pointers.aspx
http://www.augustcou...torial/ptr.html
http://www.c-faq.com/ptrs/index.html
http://www.daweidesi...in/pointers.php
http://www.eternally...t_pointers.aspx
http://www.augustcou...torial/ptr.html
http://www.c-faq.com/ptrs/index.html
#6
Re: how can I learn about pointers?
Posted 25 December 2009 - 10:10 AM
u can read a lot but try to code and practice what u read,eventually u`ll get it.
#7
Re: how can I learn about pointers?
Posted 25 December 2009 - 12:29 PM
Basically, its very simple. Pointers simply provide a way to directly access the memory of a computer. For example, lets say you want to change the value of a variable that is stored in memory. One way of doing that would be pointers.
For example...
You can add your own address to the pointer although, it can be dangarous...for example
That would change the value stored at address 100 to 10....
For example...
int *pointer = NULL; int num = 10; pointer = # // Like saying , "Pointer = the address of num" *pointer = 100; // Like saying, go to the address stored in pointer and change the value at that address to 100 now num = 100
You can add your own address to the pointer although, it can be dangarous...for example
inr *pointer = (int*)100; pointer = 10;
That would change the value stored at address 100 to 10....
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|