So I have question which may sound a bit amateur but please bear with me (as I am an amateur ). I just started diving more deeply into OO programming with C++ and have recently been utilizing references. I've always utilized pointers and admittedly have had problems utilizing them the way I really wanted to in the past. Since learning about references, all those problems have pretty much disappeared. My main question is this...
What are the benefits of using a pointer to a variable rather than a call by reference?
It seems to me that they work in a similar manner (although I do understand the differences between the two). References appear to be a bit more efficient and just are cleaner overall when using them in a program. If you could provide some examples as to when it would be a better idea to use one over the other that would be awesome. I am ready to be ejumakated.
One benefit of a pointer is that you can manipulate nearby memory addresses.
If you have:
int i = 5;
int * c = &i;
c++;
now c points to the memory address one place above (below?) where i is in memory.
edit: I know you can do this with stack allocated variables, but I am not so sure with heap-allocated variables if you can do this. It might be OS dependent, or language dependent, or not possible at all
edit: edited retarded error, lol.
Last edited by short on Fri Jul 10, 2009 1:42 pm, edited 1 time in total.
hurtshifter wrote:So I have question which may sound a bit amateur
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655
hurstshifter wrote:I see. So references are like a one woman man, while pointers don't mind jumping around from address to address.
hmm... more like you are the pimp and you tell the pointer what address he needs to be on
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655
As vince the shamwow guy would say if he had a f****** clue about pointers and references!
with regular cloths you can only use them once (References), bim bam bow!, but with shamwow (pointers) you can clean up those spills eveyday! you're gonna love this! also, pointers are made in Germany whereas References are made in Russia, BIM BAM POW, BUY THIS NOW!
if you don't have a clue what i'm going on about, explore these videos at your leisure
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
i think the best paint program would be microsoft paint + paint.NET+graphics gale + Paint shop Pro 7 + photoshop CS3, it would be called Paint Gale Pro Shop.NET,
programmerinprogress wrote:As vince the shamwow guy would say if he had a f****** clue about pointers and references!
BIM BAM POW, BUY THIS NOW!
OMG... Dr.seuss and the ShamWoW guy... ewww
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655