What are pointers for?

This is a discussion on What are pointers for? within the C++ Programming forums, part of the General Programming Boards category; i personally like using pointers...well, knowing how to use them...of course it's a lot easier to work with the stl, ...

  1. #16
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i personally like using pointers...well, knowing how to use them...of course it's a lot easier to work with the stl, but i'm certainly glad that i learned how to use them first. i believe i have a lot better understanding of my programs from know how the memory is set up and what not...

  2. #17
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    >> In my opinion, it is far more beneficial to teach more appropriate techniques first, then go into finer detail on why those techniques work.
    I just thought that pointers are not one of those finer details. I perceived that basic c++ include pointers. You have to know them just like you know int, float, etc; then build up from there.
    I would say that one examples of finer details are instructions involved in calling new (alloc, and all that stuff I'm not knowledgeable yet).
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    See, I understand if people like pointers, but I just think that it's a very bad idea to push them to newbies. You can read up more on my thoughts in the introduction to my tutorial.
    http://stud3.tuwien.ac.at/~e0226430/...ationale.xhtml
    Not IE-compatible.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    What if I say that
    if you a Comp Sci student then you have to know pointer early. If a book is designed for Comp Sci course it has to mention pointers; if it is one of "C++ for Dummies" or "Teach Yourself C++ in 21 Days", you decide.
    I would certainly dislike the idea if pointers are not taught in one of the 100-level (first year) courses in Comp Sci.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #20
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Many people are now learning Java as a first language in intro level CS courses. Are they worse off because they aren't learning pointers first? I personally don't think so.

    Pointers, while important in general, are not necessary for beginners who code in the C++ style. I would say that newbies should not even need to use new until at least the second half of their intro course. Why does someone new to programming need to know about dynamic memory allocation? Program structure and flow, loops, if statements, functions and variables are all more suitable for introductory topics.

    The strings, arrays, and other stuff is general used without being explained because otherwise the student wouldn't be able to see the results of their code. Whether you use C++ style or C style you still want to minimize the time it takes to teach these peripheral details in order to focus on the more important basic topics. Later on, when it is time to discuss the slightly more advanced language features, you can choose how much detail you want to go into. I just think that these topics should be made as simple as possible in the beginning for newbies so they can concentrate on the really basic stuff.

  6. #21
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    >> Many people are now learning Java as a first language in intro level CS courses.
    I thought they're switching to Java 'cause they don't want to use pointers at all?
    I need clarification on this one. If Java is taught first, doesn't it become the main language in the school? The whole subsequent material will then be implemented with Java? (Unless you take Intro to Fortran and the like)
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  7. #22
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The first "programming" class I took at college was Pascal. Now that its gone people take an algorithm design course or VB first. I wouldn't say either of these are the main language courses. Heck C++ is the 3rd one I've taken here and all the upper classes are implemented with C++.

  8. #23
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    I honestly don't know what they are teaching in college now. I had just heard that many universities and high schools were switching to Java as their main programming language. My experience was almost exactly like Thantos (right near Sac, too), Pascal, then C, then C++ and C++ for all upper division stuff. We even had to learn C++ on our own after the C class, and were expected to use C++ two weeks into a data structures class.

    If the point of taking Java is to avoid pointers completely, then that backs up my point of avoiding low level constructs when teaching somebody programming for the first time. Even if a student knows how to program and is just learning C++, better coding style should be taught in the beginning. That's just my opinion, but I know it is shared by many others.

  9. #24
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Our University switched to Java for the first programming course I think 3 or 4 years ago. Since then, most other courses use Java, too. One lets us choose between C++, Java and C#. One that discusses generics used C++, I think, until last semester, but now uses Java5. And so on.

    So, in general, if Java is the first language you learn, most subsequent stuff is done in Java, too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #25
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    Is it really so tough to teach someone about pointers and their proper use? I understand that many people are confused by pointers but I think the reason why is because of the black box approach. I read alot about assembly and computer architecture and low level addressing modes and when it came to pointers I understood how they worked. Maybe it is just because they don't provide enough detail or enough context. Whenever I read a C or C++ book they very rarely go into to much detail about memory architecture and addressing modes. I think they should teach basic assembly or an introduction to the instruction set before they teach a high level language. Nothing too advanced. IMO more knowledge is better.
    What is that quote?
    "A little learning is a dangerous thing; drink deep, or taste not the Pierian* spring: there shallow draughts intoxicate the brain, and drinking largely sobers us again."
    -Alexander Pope (1688-1744), _An_Essay_on_Criticism_.
    Last edited by manofsteel972; 10-14-2004 at 01:44 PM.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  11. #26
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by manofsteel972
    Is it really so tough to teach someone about pointers and their proper use? I understand that many people are confused by pointers but I think the reason why is because of the black box approach. I read alot about assembly and computer architecture and low level addressing modes and when it came to pointers I understood how they worked. Maybe it is just because they don't provide enough detail or enough context. Whenever I read a C or C++ book they very rarely go into to much detail about memory architecture and addressing modes. I think they should teach basic assembly or an introduction to the instruction set before they teach a high level language. Nothing too advanced. IMO more knowledge is better.
    What is that quote?
    I agree that this information should be taught. It is essential to the understanding of good C++ techniques.

    To me it boils down to teaching the student the best way to do something first. I highly doubt someone new to programming really understands what is going on when they use a character array to hold a string. They are only trying to understand the syntax. So if they aren't going to understand the inner workings of what they are using, why not teach them the easier syntax that also happens to be more flexible and robust. Only later, when they are focusing on how these things work, should they be exposed to the details that were glossed over in the beginning.

    In my opinion, too many programmers who think they know C++ really only use C with classes because they were taught the C way of doing things first. I doubt that those people understand pointers any better than those who were taught C++ style from the beginning. So no, it isn't so tough to do it, but it is better to wait a little longer than most courses do now.

  12. #27
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I agree that these things should be taught, but I think they should be taught after the basics. My reasons for this are threefold:
    1) People who learn on their own want to DO stuff. The best way for them to learn is a way where they have results. People who have to learn still prefer it that way, but they won't walk away if it's different.
    2) C++ is a high-level language. If you want to use it effectively, you need to think in design patterns first, how to best map your program design to a code design. Then you can think of how to map the code design to actual code. Learning pointers and this stuff teaches the latter part first, and I think that's a mistake.
    3) Building on 2, programmers, especially hobby programmers, often get caught up in the details. They worry too much about minor stuff and don't get anything done. Again, by teaching the high-level techniques first, you can get them to think big in the first place.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #28
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    I understand your point of view. I guess in my mind, I am able to grasp the concepts better because I can visualize the inner workings. I can see how a character array would be represented in memory. I can see they are a series of 1 byte chunks and that that they are stored in a linear memory area that begins at some address. that address being the pointer. I can see that bye adding 1 byte or 2 bytes or 3 bytes I can access the 1st second or 3rd char variable. in the string. I can see that it has a specific size and that if i index past the end I will end up in some other memory space. Everyone has different learning styles I guess this is just mine. To me having something to anchor my knowledge to is less discomforting then floating on the knowledge of it works somehow but all I need to to do is put this symbol before it to make it a pointer and then put this other symbol before it to make it a reference. Granted it is all a time constraint. What makes for efficient learning? How can I cram the most knowledge into my head in the least amount of time and have it stick? I guess I am stuck in the scientific mode of how does it work so I can understand how everything else works.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  14. #29
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    The fact is, C++ is far easier to learn than C. And I'm going to take advantage of that in this tutorial. All I expect of you is to accept that you're using things without knowing how or why they work. Explanations will come in time.
    I'm extremly glad i'm learning C first. I've found that an indepth understand of how C works, is great to understand other languages, scripting and otherwise. C++ is no exception - regardless of of the extra libraries and data structures B.S. used to make it "simplier".

    Many people are now learning Java as a first language in intro level CS courses. Are they worse off because they aren't learning pointers first? I personally don't think so.
    Serioulsy if your studying computer science shouldn't you study computer Science. I'd love to see some of those first year students have a look at the JVM and the ubelievable usage of pointers its said to make use of.
    Java is a lanuguage built atop C and C++. It is the product of someone's imagination in an attempt to facilitate programming and be the the new PL-1. As it result its failed miserably(regardless of how much shelf space it takes up). Have you looked at JAVA 5?

    The point is C (and more importantly the understanding of pointers in C) gives you unbelievable power and advantage when coding. Sure if you want to use a language that abstracts all of that for you, fine, But then why bother going into computer science at all. In fact forget java and learn HTML.

    Java is good for what it is, a dumbdowned version for RAD. Serioulsy ppl need to stop comparing it to C there is none.


    What makes for efficient learning? How can I cram the most knowledge into my head in the least amount of time and have it stick? I guess I am stuck in the scientific mode of how does it work so I can understand how everything else works
    ditto. even if i am a hobbyist programmer
    Last edited by caroundw5h; 10-14-2004 at 02:57 PM.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  15. #30
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Of course pointers and other low-level stuff should be taught. Of course it helps you understand what is going on. Of course computer science is more than just learning the syntax of a language.

    The argument is that when teaching C++ specifically, the low-level information should be not used to explain what to do in your program, but instead should be used to explain how your program works.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21