0

hi everyone))
Please tell me - where is the mistake here -

struct address  {char* city ; char* street; int housenumb ;};
  struct addinf  {int age; struct address*  address;};
  struct student {int number; int kurs; char* name ; struct addinf* addinf;} stud;
  
  
  stud.number=1;
  stud.addinf.address.housenumb =123;

thanks in advance)

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by vedro-compota
Featured Replies
  • 1
    Narue 5,707   6 Years Ago

    addinf and address are both pointers to structures, so you'd need to dereference the pointer before accessing members: [code] (*(*stud.addinf).address).housenumb = 123; [/code] Alternatively, the arrow operator does this for you in a much more convenient manner: [code] stud.addinf->address->housenumb = 123; [/code] Note that those pointers must point to something … Read More

1

addinf and address are both pointers to structures, so you'd need to dereference the pointer before accessing members:

(*(*stud.addinf).address).housenumb = 123;

Alternatively, the arrow operator does this for you in a much more convenient manner:

stud.addinf->address->housenumb = 123;

Note that those pointers must point to something first. Pointers aren't magic.

Edited by Narue: n/a

Votes + Comments
0

Note that those pointers must point to something first.

good advice)) but what about this - it isn't right too.... -

if (stud.addinf->address->street == null) putchar(a);

why it's so?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.