user3123327
user3123327

Reputation: 13

pointers to the array of structures

What is the array of pointer to the structure?

is it something like this:

StructureName objectname[size];

int *ptr;
ptr=objectname;

Please confirm me with this.

Upvotes: 0

Views: 71

Answers (2)

Joseph Mansfield
Joseph Mansfield

Reputation: 110658

I'm assuming you meant ptr to be a StructureName*, otherwise your code won't compile.

No, that is not an array of pointers to a struct. What you have done is used array-to-pointer to conversion to assign the array objectname to ptr. This makes ptr a pointer to the first element of the array.

An array of pointers to struct is something like:

StructureName* objectname[size];

Here, we are declaring an array objectname that has size pointers to StructureNames. The elements of the array are pointers. This makes it an array of pointers.

On the other hand, your title asks about a pointer to an array of structs, in which case it would look like this:

StructureName (*objectName)[size];

Upvotes: 0

Shoe
Shoe

Reputation: 76240

This is the array of pointers to some structure:

StructureName* objectname[size];
//           ^

which is the closest thing I can think of when you refer to:

array of pointer to the structure

Upvotes: 1

Related Questions