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

    Joined:
    Oct 5, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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