i understand int cars[23]; can be accessed using pointer notation such as...
int cars[10];
int *carz;
*(carz+1); // carz[1];
im curious as to what the equivalent pointer notation would be for a structure..for example
struct car
{
int wheels;
float gas;
float engineHP;
};
struct car cobalt;
cout << cobalt.engineHP << endl; // what's the equivalent of this in pointer notation?
lochnessmonster
0
Junior Poster
Recommended Answers
Jump to Post
struct car cobalt
. car is not a pointer. I believe you want something like so,struct car cobalt[23]
. In that case you could use the same notation as for regular arrays. For class object there is a special pointer operatorcobalt->gas
. Notice the "->" operator. For …
Jump to PostThat access the first element. If you want to access the nth element you would do something like these :
…Car car[25]; int n = 5; //for example car[n].gas; //option # 1 (car + n)->gas; // option # 2 ( *(car + n) ).gas; //option # 3
All 6 Replies
mrnutty
761
Senior Poster
lochnessmonster
0
Junior Poster
mrnutty
761
Senior Poster
VernonDozier
2,218
Posting Expert
Featured Poster
lochnessmonster
0
Junior Poster
VernonDozier
2,218
Posting Expert
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.