pointers to structs

Discussion in 'C++' started by kranta92, Oct 5, 2010.

  1. kranta92

    kranta92 New Member

    Oct 5, 2010
    Likes Received:
    Trophy Points:
    if i write something like this:

    typedef struct {int x,y;} str;


    str A, *p = &A;
    int *p2 = &A.x;

    then cout<<*p2 prints the value of A.x
    and cout << p2 prints the address of A.x
    but if i write cout<<*p->x , compiler says "illegal indirection"
    and if i write cout<< p->x i get the value of A.x

    so why is that and how can i get the address of A.x using p pointer ?

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice