• Forum
  • Lounge
  • I grasped pointers :D it took two months

I grasped pointers :D it took two months from complete c++ ignorance!! how long it take you?

Pages: 123
I feel amazing.

There's nothing more rewarding than a code working like you didn't really expect it to.

I also hope that brand new n00bs like me who are struggling can see that it took two months at a few hours a day and even though you see what they are straight away its not to be immediately understood.

anyway i demand my yellow belt in c++ who is in charge with the belting ceremony here?
Last edited on
The ghost of Dennis Ritchie is responsible for handing out pointer-related prizes.
It took me a fair amount of time to grasp pointers as well. It's weird but now that I understand them, they seem incredibly simple.
I think its too abstract for the front of the brain to deal with, and explaining is hard because the persons brain who you are explaining them too doesnt know how to store the information, anyway,did denis richie put my yellow belt in the post?
Last edited on
It's actually really simple though. It's just a variable whose value is an address in memory (usually the address of another variable). Understanding that was easy, but understanding when to use them and why was hard.
thats the key too teaching the beginner then
Yeah, you would explain that pointers are a mechanism for getting around C's pass-by-value system (because the address of the variable is passed instead of its value) which means you can modify the original rather than the copy, and also that you can pass around large structures without making copies, which would be very slow.

Other than that, you should avoid pointers as much as you can. They're unsafe and error-prone and can make programs harder to reason about. Generally you should try to write your functions so that they don't modify anything that can be accessed from anywhere else in the program (so, they take a list of parameters and return a value, rather than modifying the parameters). In practice you often can't do that, and your functions will have to have side-effects (meaning they touch global variables or modify the values of their parameters), but where possible you should avoid it, because it makes the program more predictable. It also helps the compiler with optimisation. So, to summarise, only use pointers where you absolutely must, and try to avoid writing functions with side-effects.
Well for the most part because of me doing web development pointers really weren't that hard due to domains are kind of like pointers in the regard that your domain name (pointer variable name) is pointing to your sever (address of variable). Well that is how I picked up on pointers, but I don't use them that much so I don't think I can say I fully learned pointers.
closed account (o1vk4iN6)
I always understood pointers, I learnt x86 assembly before I learnt C++ :P.
Did you at least learn something like 6502 assembly before that?
My first code was machine code. And I wrote it with a steady hand and a magnetized needle. Like a sir.
about my yellow belt
you would explain that pointers are a mechanism for getting around C's pass-by-value system
but in C++ you've got references, ¿how would you explain pointers then?
closed account (zwA4jE8b)
Understanding pointers came fairly easy to me. Although at first, I didn't do such a great job deleting them :P I just always though of them as like a road-sign pointing to your destination!
Nothing would change, you would just explain references as another (and sometimes better) way of achieving the same goal. The problem with references is that AFAIK there's no way of indicating failure via return value like you can with pointers by returning NULL, so you have to throw an exception, and I don't like to use exceptions.
Pointers can be used as optional output arguments.
If it failed you could return an invalid object, however ¿why is your function returning a pointer in the first place?
Those are kind of especial cases, so it would be seen as `pointers are that obscure feature that you'll likely wouldn't need'

The principal function of pointers is to point.
That way you create relationships between objects, that can change at run-time.
When I first started pointers gave me a hell of a time understanding for some reason. But then I took a computer architecture class and we talked about indirect addressing and it just hit me and ever since then they've just seemed super simple, as they really are.
I think that for pointers in specific, it took only a few minutes to grasp the concept - the tutorial on this site makes it pretty obvious how they work. The uses and design patterns took a few days after that, but for the most part it isn't hard to grasp the concept of scoped stack variables and using new/delete properly. As for when to use and when not to use pointers, I learned quickly that most of the C++ standard library makes it pointless to use pointers, and I found an article on this forum about when to sue them. They're actually hardly used for most cases because the standard library handles it all for you.

And I've never understood the whole "optional parameters" thing with pointers - function overloading exists, and if you design it right and don't mind the minor overhead, you can have no code duplication.

A lot of people say pointers give you power. Sure, guns give you power, but you usually end up shooting something by mistake.
Last edited on
so to get my c++ yellow belt do i have to beat someone of similar skill at a bout of 'competitive programing? is there a belting ceremony after that??
Unlike Java, there isn't a C++ certification you can get. And besides, most programmers are hired based on experience. Find things that need doing, do them, and add them to your resume.
Pages: 123