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?
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?
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.
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.
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.