Learning C++

Viewing 8 reply threads
  • Author
    Posts
    • #5486
      MatP
      Participant

      Hey πŸ™‚

      So I’m in the process of learning C++. I have a small problem though.

      I find it difficult at times to understand the point of pointers. Perhaps it’s simply the textbook I am using doesn’t provide a good explanation or a good example. I just can’t think of any reason I’d want to use them in a program I was creating myself.

      Now I’m sure there must be plenty of reasons out there as I’ve seen them in examples of other code so I’m wondering if anyone has a good resource to teach this aspect of programming or could provide an example problem that requires a solution using pointers?

      Thanks for the help!

    • #34699
      Xen
      Participant

      Have you ever tried to pass an array as an argument to a function? How do you do this?<– Think on this for a moment, and try to find a solution for it.
      Also, how do you allocate dynamic memory?

      I learned C programming (I’m not very good at C++ though I can read and understand the code) and especially pointers from a lot of books and online articles, so I can’t direct you to any absolute resource. However, a good starting point will be to clear your concepts pertaining to arrays and strings and how they’re stored in memory and then move to pointer. Learn all about pointers,pointers to arrays/strings, array of pointers (different form pointer to arrays), function pointers, pointers to other datatypes and try to compare how using a pointer is different from using that variable in a normal way. At each point try to visualize what’s happening in the memory.

      Here are some resource which might help you.
      http://www.cprogramming.com/tutorial/lesson6.html
      http://www.augustcouncil.com/~tgibson/tutorial/ptr.html
      http://c-faq.com/ptrs/index.html
      http://c-faq.com/malloc/index.html
      http://c-faq.com/aryptr/index.html

    • #34700
      zeroflaw
      Participant

      With pointers you have full control over the memory in your program. Also sometimes you need to work with memory addresses, they can be stored in pointers.

      And like Equix3n said, how do you allocate dynamic memory? Or how do you access newly allocated memory? You need pointers for this. It’s also needed when implementing polymorphism in your program. You have different types of objects, and sometimes you don’t know the type in advance or want to change it. You can have your pointer point to a different type of object then.

      There are also lots of functions from different API’s that need pointers as arguments.

    • #34701
      MatP
      Participant

      Thanks for the help guys πŸ™‚ I appreciate it. I will definitely take a look at those links over the next few days.

      I hadn’t considered a lot of what you’ve given me. I’m still fairly new to C++ (and programming in general, haven’t done anything beyond beginner stuff before) so there are a number of concepts still quite foreign to me. Anyway, I will continue reading/learning!

      Thanks!

    • #34702
      Xen
      Participant

      You might also want to consider the following free lectures from Stanford.
      CS106-B Programming Abstractions: Teaches C++ programming. Natural successor to CS106-A which teaches programming methodology in Java
      http://see.stanford.edu/see/lecturelist.aspx?coll=11f4f422-5670-4b4c-889c-008262e09e4e
      http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/FE6E58F856038C69

      CS106-A Programming Methodology
      http://see.stanford.edu/see/lecturelist.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111
      http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/84A56BC7F4A1F852
      I haven’t gone through both of the above, but I checked the first video of CS106A and I guess you’ll be fine if you jump straight into CS106B.

      I’m currently going through CS107. Excellent stuff. It’s a must if you want to learn some advanced programming basics. Highly recommended. It basically teaches what happens under the hood, so don’t study from it if don’t already know basic C/C++.
      CS107 Programming Paradigms
      http://see.stanford.edu/see/lecturelist.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee
      http://www.youtube.com/user/stanforduniversity?blend=2&ob=4#g/c/9D558D49CA734A02

      Edit: Just found a really good paper or Pointers. Do read it.
      cslibrary.stanford.edu/102/PointersAndMemory.pdf

    • #34703
      MatP
      Participant

      Awesome, I will definitely look over all of those videos/the paper linked when I’m at home and have some time. Thanks for the links and all the resources you’ve provided so far. Slowly but surely I’ll figure this stuff out and get into more advanced concepts πŸ™‚

    • #34704
      MatP
      Participant

      So I’ve read over some of the content you linked in your first post Equix3n- and I’ve got to say that the text book I’m reading, which has been mostly pretty good, is really terrible at explaining the concept of pointers.

      Thanks so much for your links πŸ™‚

    • #34705
      Xen
      Participant

      Which book are you referencing?

    • #34706
      MatP
      Participant
Viewing 8 reply threads
  • You must be logged in to reply to this topic.

Copyright Β©2021 Caendra, Inc.

Contact Us

Thoughts, suggestions, issues? Send us an email, and we'll get back to you.

Sending

Sign in with Caendra

Forgot password?Sign up

Forgot your details?