Structures

I'm working on understanding structures, but I'm a little confused on some parts. If I have a code like this:
1
2
3
4
5
6
7
8
9
10
11
12
struct DogSize 
{ 
  int height ; 
  float weight; 
}; 
struct DogType 
{ 
  char breed; 
  DogSize size; 
  double price; 
}; 
DogType dog1, dog2; 


So if I were to use a variable dog1.breed, it would give me a char, right? But what would happen if I used dog2.size? How does that work? And what if I use three, like dog1.size.weight? Would it make a difference that size and weight are under different structs?

I appreciate any help.
Last edited on
So if I were to use a variable dog1.breed, it would give me a char, right?

yes

But what would happen if I used dog2.size?

will give you a DogSize.

and what if I use three, like dog1.size.weight?

will give you a float


in a struct you simply group different datatypes under 1 name. think of the struct you created as of a datatype, just like int, char, ...
so if you use DogSize in your 2nd struct you basically use your own datatype DogSize there, the same way you would use int, char, ...
Last edited on
Okay I see now. Thank you very much!
Last edited on
Topic archived. No new replies allowed.