What Are Pointers? (C++)



A bit different from me, but I felt like I needed a reference video that explained a few things about pointers. Included are the very basics, memory allocation, problems to avoid and smart pointers.

This video is aimed at those earlier on with their programming journeys.

https://discord.gg/WhwHUMV
Blog: http://www.onelonecoder.com
Twitter: @javidx9
Twitch: javidx9

32 thoughts on “What Are Pointers? (C++)

  1. I don't know if it's gonna be of use to anyone, but I personally prefer to think of declaration like
    T *t_ptr;
    as of an equation. It means if you dereference t_ptr, you'll get something of type T, and therefore t_ptr itself must be of type pointer to T. It facilitates understanding more complex cases like function pointers or arrays of pointers easier. Just remember that function call () and indexing [] operators have higher priority, and thus are executed first, unless you change the order with parentheses. For example, you can read the declaration
    T *f();
    as follows: if you call f and dereference the result, you'll get T, therefore f is a function that returns a pointer to T. On the other hand, the declaration
    T (*f)();
    means if you dereference f and call it, you'll get T, therefore f is a pointer to a function that takes nothing and returns T.

  2. I have had many interns who don’t understand the concept of pointers. And initially I didn’t understand because it so fundamental to CS. Then I found out that college students don’t get a semester of assembler programming anymore. And then it fell into place. So initially I took an hour to bring them up to scratch. And during those sessions I noticed that the * is very confusing to them in C (C++) as it basically means two different things. As an assignment and an operator for dereferencing aka getting the value from that address the pointer is pointing to. Then all of them understood.
    But I still am amazed how you can get through 4 years of college in Computer science and not fully understand the fundamentals of a computer.

  3. This guy is a genius, he is gentle, and wants everyone to learn at their own pace and on their own terms. He explains things like a gentleman and holds no judgement or arrogance towards others. He is in fact a PhD holder in Computer Science, as well as an experienced professional in the real world. It does not get any higher for anyone. He is undoubtable worth his weight in gold. Creative minds like this belong on the edge of technology and business

  4. Even casting my char pointer to (int) wasnt enough. The compiler shows a "lose precision" error. But in any case, nice tip on not creating pointers to vectors, that one was sweet.

  5. Circa 1985-ish, I started down the path to a CS degree. It was probably called something like IS or MIS at the time. The school I was at structured this so that first-year programming courses were taught in Pascal. Second-year was in C. Of course, we didn't call it "K&R C" at the time, because the ANSI standard wasn't complete yet.

    I noticed during the C part of the program that in every class, there would inevitably be someone sitting in the front row who, sometime well past the first week or two of class, would suddenly ask "Wait. What's a pointer again?"

    Pascal had pointers — oversimplified and of limited utility, but clearly pointy pointers used to point at things. How do you make it as far as an upper-division class in a discipline that critically requires a good understanding of pointiness and then ask "wait, what's a pointer?" This would bring the entire class to a screeching halt for a week while the Prof set about clearing up the confusion of a student who would inevitably take a W anyway. This happened in at least three different courses, and with a different person each time.

    And THAT, my friends, is why I bailed on software as a career and became a Certified Netware Administrator and embarked on a career in Ops, where our job is to make the product look like it works properly.

  6. @30:00 The & symbol to refer to "pass by reference" is confusing from people coming from C where that specifically means "memory address of". I like it, but it's sort of hand-wavy syntactical magic when you realize what it's actually doing.

  7. 3:14 There is no "pointer" keyword in C++. If I was a beginner I'd be confused af. And does it take so much energy to add the semi-colons? I guess this is pseudo-pseudocode.

  8. i might be stupid, but even though I'm absolutely fine with dynamic memory allocation and freeing in C, I can't make sense of this C++ notation

  9. You'd think that someone explaining pointers would respect the distinction between the letter, "O", and the numeral, "0". "Oh" and "zero" ain't the same thing; they just look the same.

Leave a Reply

Your email address will not be published. Required fields are marked *