Thread: Good pointer learning tool?

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    14

    Good pointer learning tool?

    Hey, I don't have any specific coding question, but I am having a lot of trouble with pointers in my class and was wondering if anyone knows of a good tool or website to help learn. I've been rummaging around other websites but it isn't really "clicking" for me. I feel like I am falling behind but my professor's office hours are during another class. Any hints or tips pertaining to pointers would be more than welcome as well.

    I do know that pointers' contents are just addresses of other variables, but I'm having a lot of trouble knowing how and when to use them as parameters with their symbols (*, &).

    Thanks in advance!
    Last edited by Devolution; 03-11-2009 at 02:49 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Linked lists (if you can). Find a linked list tutorial and try and write a basic program to add, remove, and show all nodes.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A small guide:
    int x = 10;
    int* p = &x;
    *p = 20;
    After this, x is 20, and *p is 20.
    Before, x is 10.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    the best way to understand pointers is to study a little bit of assembly language

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by baccardi View Post
    the best way to understand pointers is to study a little bit of assembly language
    makes no sence for me
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by baccardi View Post
    so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work
    you guessed wrong
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work
    I disagree. Looking at how one implementation works is by no means a good way to learn how they work overall. Not to mention there is usually no concept of "pointers" at such a low-level.

    That's like learning how to drive by looking at how the steering column in your car works.
    Last edited by zacs7; 03-11-2009 at 04:10 PM.

  9. #9
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    in c '&' is the address of operator which gives the address where the variable in memory is stored.'*' is the value at address operator.it means if you use '*' and '&' with a variable it will give you the variable's value.
    for eg.
    Code:
    int i=10;
    printf("%u %d",&i,*(&i));
    this will output the address and the value of i(which is 10).
    Now this means that if you want to have access to the address of the variable you can use these operators.and once you have access to any variable's address you can change it to other value or can do some operations upon it.thus if you want to change the value of a variable or do some advanced operations you need to pass the address of the variable.

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by Elysia View Post
    A small guide:
    int x = 10;
    int* p = &x;
    *p = 20;
    After this, x is 20, and *p is 20.
    Before, x is 10.
    int * q;
    q = p;
    This is pointer assignment for pointers with the same level of indirection, since we're copying the value of p (some address), not p's address.
    ++(*q);
    *q++;
    Know the syntax for your increments and decrements.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by whiteflag
    Know the syntax for your increments and decrements.
    Building on whiteflag's examples, find out the difference (if any) between ++*q, ++(*q), *q++ and (*q)++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Jul 2008
    Posts
    11
    This is really cool, when you can follow this guy you will be the pointer master . I followed a lesson or 4 or so, and found it really "clearing up the mist". If i find some more time i'm going to watch the whole "show"

    http://www.youtube.com/watch?v=Ps8jO...eature=related

    B.t.w. i think i found the link on this forum, somewhere...

  13. #13
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    I have to see some formal stuff in order to understand things, and the following helped me a lot to understand pointers:

    A variable is a 4-tuple consisting of name, size, address and value.
    A pointer is a variable whose value is the address of another variable.

    For C, this is almost true. On the other hand, you don't need to fully grasp the concept of pointers right at the beginning. Read through the pointer chapter of whatever book you are using to learn C, but don't try to understand everything. When you're actually dealing with pointers (writing a linked list is the common example), stick to syntactical rules. When you're used to the syntax, read the chapter again.

    Pointers are so difficult because the first time you hear about them, you probably don't have the slightest clue about their usefulness. First find out why they are useful and how to use them syntactically, then try to understand them.

    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  2. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Learning DirectX 6.1. Still Good...?
    By Cheeze-It in forum Game Programming
    Replies: 5
    Last Post: 05-21-2002, 04:46 PM