Sunday, 15 September 2013

Accessing element of an array of struct.

Accessing element of an array of struct.

So I have an struct
struct car{
string ownerName;
float price;
int year;
};
and I declared an array of these structs car *cars = new car[1000] Each
car has an index, for example, the car with index 0 has name John Smith.
So, my question is knowing the name of the owner how do I access the index
of the car. I know that the other way i would write cars[0].name, to get
the name, but how would i do it backwards?

No comments:

Post a Comment