| | |
confusion
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
My biggest problem right now in understanding c++ is pointers.
Im curious to its specific funcionality, so instead of doing somthing like
p = &x
then calling x using *p, why couldn't you just say x = p?
Im pretty sure my syntax is wrong, but hopefully i'm getting my question across properly. Thanks!
Im curious to its specific funcionality, so instead of doing somthing like
p = &x
then calling x using *p, why couldn't you just say x = p?
Im pretty sure my syntax is wrong, but hopefully i'm getting my question across properly. Thanks!
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
pointers are just like ordinary variables that carry the address of other variables and objects. you need pointers because sometimes when passing information within your program, let say from a function to a function, you dont want to pass all the data, instead you want to pass the address of that data in memory, that is when pointers become useful. they are also used for memory management as they are able to address to memory.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
i have an apple analogy for you, if you ask for an apple, i can bring it to you, or i can say that it is in the kitchen and you can go and grab it. i am not a good c++ programmer though, but it is easy to understand things when some one is as bad as you
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
I also had a big problem understanding pointers, but it's not that hard:
pointers are just like any other variables when you use the asterisk (*) before them - which leads to the value in the address they hold.
They're useful because, just how serkansendur said, you can save computer memory when passing them to functions (because you send the whole address and not a copy of the variable), and you can manage the variables' values throught them.
Passing an address to a pointer in a function is similar to sending a reference (with the prefix &) to a function, except that a reference can't get a new address to refer to.
pointers are just like any other variables when you use the asterisk (*) before them - which leads to the value in the address they hold.
They're useful because, just how serkansendur said, you can save computer memory when passing them to functions (because you send the whole address and not a copy of the variable), and you can manage the variables' values throught them.
Passing an address to a pointer in a function is similar to sending a reference (with the prefix &) to a function, except that a reference can't get a new address to refer to.
Look at the excellent tutorial by Julienne Walker:
http://eternallyconfuzzled.com/tuts/..._pointers.aspx
http://eternallyconfuzzled.com/tuts/..._pointers.aspx
![]() |
Similar Threads
- Hash Table Confusion (C++)
- Container Adapter Confusion (C++)
- confusion with char datatype (Java)
- please remove my confusion (Networking Hardware Configuration)
- Confusion (IT Professionals' Lounge)
- confusion in a coding (C++)
- Memory allocation confusion (C++)
- confusion (Java)
- Microsoft Windows Longhorn Confirmed Leaked! (IT Professionals' Lounge)
- Apache For Windows (Linux Servers and Apache)
Other Threads in the C++ Forum
- Previous Thread: Network Programming - send/recv and Timeout Query
- Next Thread: How to Find The user input ?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






