Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

How to pass pointer to array of structure?

struct SomeStruct
{
   int value1;
   int value2;
}

SomeStruct data[10];

Passing pointer to first array entry would be:        &data[0]
Passed argument would be:                                    SomeStruct  * addr

Am I correct?
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Example.

It can be either a const or non-const pointer. Pass as const unless you plan to modify it.
struct SomeStruct
{
   int value1;
   int value2;
};

void foo(SomeStruct const *)
{
}

void bar(SomeStruct  *)
{
}

int main()
{
	SomeStruct data[10];

	foo(&data[0]);
	bar(&data[0]);
}

Open in new window