I don't get pointers in structures. Just a little problem

See, you have a structure like so:

typedef struct EXAMP

{

double x,y,z;

} EXAMP;


and then you get this:

EXAMP *xamp


what does this mean? It doesn't make sense that you place the memory location for x, y and z into one pointer. Or is the xamp pointer pointing to the beginning of the struct? I'd really appreciate help. I've spent lots of time trying to get this.




Comments

  • You'll need to allocate the memory before you can use the pointer.


    Try:


    EXAMP *Example;


    Example=(struct Example *)malloc(sizeof(EXAMP)*nNumberInArray);


    -Xotor-


    : See, you have a structure like so:

    : typedef struct EXAMP

    : {

    : double x,y,z;

    : } EXAMP;


    : and then you get this:

    : EXAMP *xamp


    : what does this mean? It doesn't make sense that you place the memory location for x, y and z into one pointer. Or is the xamp pointer pointing to the beginning of the struct? I'd really appreciate help. I've spent lots of time trying to get this.





  • : You'll need to allocate the memory before you can use the pointer.



    : Try:



    : EXAMP *Example;



    : Example=(struct Example *)malloc(sizeof(EXAMP)*nNumberInArray);



    : -Xotor-



    : : See, you have a structure like so:

    : : typedef struct EXAMP

    : : {

    : : double x,y,z;

    : : } EXAMP;



    : : and then you get this:

    : : EXAMP *xamp



    : : what does this mean? It doesn't make sense that you place the memory location for x, y and z into one pointer. Or is the xamp pointer pointing to the beginning of the struct? I'd really appreciate help. I've spent lots of time trying to get this.



    :

    :



    I have a little piece of code at my website which uses pointer to structure.

    gurumuhk.tripod.com/codes/ptrstruk.c






Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories