Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm a student at the University and I'm taking the Data Structures class. When learning linked lists and doubly linked lists, did you guys feel you learned a deeper understanding of pointers, dynamic memory allocation, and memory usage? I just created my first linked list(it was actually a doubly linked list) and it seemed to me like a real eye opener. Your thoughts?

share|improve this question
1  
When I was learning C, my mentor told me I should always remember the 3 most important things a programmer needs to know to write C code. Pointers, Pointers, and...Pointers. –  Alan Oct 5 '10 at 5:18
2  
So many useful techniques come from using pointers. –  Sir_Blake_ Oct 5 '10 at 7:08
add comment

closed as not constructive by Robert Harvey, Mark Trapp Oct 21 '11 at 22:51

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

9 Answers

Pointers really clicked for me when I was working with the Quake 3 source which was written in C. I don't believe the specific task that you used to learn pointers (or anything) really matters. Simply by using pointers and trying to understand them it will eventually click.

share|improve this answer
    
Trying to understand them is the best way to learn just about anything. Good answer. –  Chris Dec 1 '10 at 13:30
add comment

I thought that I did until I took my first assembly programming language class. The different addressing modes really made it click for me. I didn't gain a deeper understanding until reading "Expert C Programming: Deep C Secrets" by Peter van der Linden. After you read your way through the whole book (chapters 4, 7, 9, and 10 in particular), you will have a complete understanding. This book is pretty much the Jedi Knight training course for C programmers.

share|improve this answer
2  
Agree, after you have written assembly code using address registers, then pointers become "real" to you. –  tcrosley Nov 13 '10 at 17:19
add comment

To be honest, I'm surprised that people find pointers hard to learn and/or confusing.

There are plenty of real-world analogies that most people find entirely un-confusing. For example, what is so hard about some gps coordinates written on a piece of paper?

  1. The piece of paper is not the coordinate information.
  2. The paper just stores the coordinates.
  3. The paper also has a location.
  4. The coordinates are not the location they point at. They are coordinates, not a physical location.

What is the big deal?

share|improve this answer
add comment

Not particularly. By the time I got to a formal Data Structures class in college and started learning stuff like linked lists, I'd already been hacking around with pointers in Pascal and C for several years, so I already had a feel for how they work.

share|improve this answer
add comment

Pointers still have yet to click for me. I know what they are, and I know how they're used but I've had to have that "AH HA!" moment with them... sigh

share|improve this answer
    
keep at it and have fun! –  Sir_Blake_ Oct 5 '10 at 7:11
add comment

Yes. I've been doing a "C rerun" of sorts, brushing up on the language - and I found linked list exercises helpful in getting familiar with many pointer idioms. Here's the link if you're interested - http://cslibrary.stanford.edu/ . If you're doing the exercises in there, make sure you do them all, in sequence.

share|improve this answer
    
The Pointers And Memory.pdf is by far the best introduction I found on pointers and dynamic/static memory allocation. Besides, it's fun to read. –  Oliver Weiler Nov 13 '10 at 18:26
add comment

I wish everyone learned assembly language before moving on to the high level language. My understanding of pointers when I started programming and now is the same. It's very easy when you think of what the C/C++ does for you what 8085 assembly language can't. If you felt you understood "more" then you don't know more yet. But if you instantly recognize how easy concept it is then you got it!

share|improve this answer
add comment

Implementing a linked list helped me learn pointers somewhat, but was slightly overshadowed by the initial confusion of declaring a pointer within a node using a type that was currently being defined.

struct Node {
    int data;
    struct Node* next;  /* <= !!!  */
};
share|improve this answer
add comment

I learned about dynamic memory from the old DOS days. I remember the video buffer address as B800:0000 through B800:7FFF. Before drawing any popup windows I would copy off the video memory that was going to be overwritten and when, the window closed I would swap that memory back in. I remember thinking back then that this was the neatest thing. Thank godness we don't have to do that today.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.