# Is there any way to group variables like group.variable as you can in Java/Delphi

I'm writing a sketch which does some calculations on measured variables, and it's based on a similar program written in Java like c = A.Ux + B.Uz; Where A&B have various parameters Ux,Uy,Uz etc In Delphi this notation can be used either for parameters of classes or variables in a group. Looks like there's something similar in Java. It's a tidy way to organise and manipulate variables when there are lots of them and move them between methods without having huge numbers of arguments.

Is there any way to do this in the Arduino Wiring language? I don't seem to find anything online, but I'm probably phrasing the question wrong. Thanks in advance, Brian

What you are looking for is a `struct`:

``````struct foo {
uint8_t Ux;
uint8_t Uy;
uint8_t Yz;
};
``````

Then:

``````struct foo A;
struct foo B;
``````

And:

``````A.Ux = 3;
B.Uz = 48;

int c = A.Ux + B.Uz;
``````

When calling a function you should really use either pass-as-pointer or pass-as-reference to avoid unnecessary copying:

``````// By Reference
int normal(struct foo &arg) {
return (arg.Ux + arg.Uy + arg.Uz) / 3;
}

int avg = normal(A);
``````

Or:

``````// By pointer
int normal(struct foo *arg) {
return (arg->Ux + arg->Uy + arg->Uz) / 3;
}

int avg = normal(&A);
``````