Thread: pointerz

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    pointerz

    i just need to know what a pointer really does...
    can you correct me if im wrong...

    so if i was to write something like..

    Code:
    struct char *house[] = {
                                house1
                                 house2
                                 house3
                                         }
    does this means that if i was to do

    Code:
      if (char = p_house)
           house3 = blah;
    will that work if not then can you explain to me like if a 3 year old kid on how to understand .... thanx

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    A pointer points to a memory address, unlike variables which contain the actualy value.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Perhaps this explains a little bit on pointers and structures.

    Code:
    /* Definition of a structure */
    struct datastruct
    {
        int data1;
        int data2;
    };
    
    /* Pointer to structure */
    typedef struct datastruct *pdatastruct;
    
    /* Instance of structure */
    struct datastruct mydatastruct;
    
    /* Pointer to instance of structure */
    pdatastruct *pmydatastruct;
    
    /* Let pointer point to mydatastruct */
    pmydatastruct = &mydatastruct;
    
    /* Access to members of structure */
    mydatastruct.data1 = 1;
    mydatastruct.data2 = 2;
    
    /* Acces members using pointer */
    pmydatastruct->data1 = 3;
    pmydatastruct->data2 = 4;

  4. #4
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Everyone says pointers are essential....but I can't find a good use for them. Maybe thats cause I'm still programming text based RPGs

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >but I can't find a good use for them.

    Just take a look at datastructures like trees, linked lists, graphs etc.

    Read some tutorials on C and you'll many applications of pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointerz
    By xlordt in forum C Programming
    Replies: 6
    Last Post: 01-11-2002, 08:31 PM