1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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