-
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
-
A pointer points to a memory address, unlike variables which contain the actualy value.
-
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;
-
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:p
-
>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.