?
2009-12-07 16:17:17 UTC
So I see 2 ways to tackle this, I can either write a structure or an array... which one should I do?
I understand that these would normally be two different data types (integer and string) but what if I said that a male is given 0 and female is given 1. Now I could have all the same data types, so I could do either of the following:
ARRAY.....
int person(4) = {0, 72, 175, 30};
- this creates a 30 year-old, 6 foot tall (72 inches) male who weighs 175 pounds
STRUCTURE.....
struct person {
int gender;
int height;
int weight;
int age;
};
person woman;
woman.gender = 1;
woman.height = 60;
woman.weight = 110;
woman.age = 22;
- this creates a 22 year-old, 5 foot tall female who weighs 110 pounds.
So both of these should work, but which one is better? or are they the same? Could someone please explain when should you choose to create a structure, and when should you choose to create an array?
Another related question: I know an array is a contiguous block of memory, is a structure as well?
Thanks! - I will choose best answer!