# Thread: How to create array structure with memebers of different size

1. ## How to create array structure with memebers of different size

All,
I need some help creating an array of structure whose memory is allocated at run time. Also the structure has members whose size are different and again memory is allocated at run time. For example.

Code:
```typedef struct{
double *a
double *b
}test;

where test is an array of structures determined at run time such that
test[0] would have members as
a[10]
b[20]

test[1] would have members as
a[40]
b[60]

test[2] would have members as
a[15]
b[25]```
size of each arrays a and b within the structure are also determined at run time. Would appreciate if someone could help me out here.

Thanks

pk68

2. You mean like:
Code:
```test *data = malloc(sizeof(test) * 5);
data[0].a = malloc(sizeof(double) * 10);
data[0].b = malloc(sizeof(double) * 20);```
?

3. It needs to be

data[0].a = malloc(sizeof(double) * 10);
data[0].b = malloc(sizeof(double) * 20);

data[1].a = malloc(sizeof(double) * 20);
data[1].b = malloc(sizeof(double) * 40);
....
....

Not sure if this is possible

4. Sure it's possible. What can't you figure out how to do?

Quzah.

5. I would appreciate if someone can provide the syntax to allocate memory to the structure and the structure members dynamically. I am new to C programming and struggling a little to get this going. The function I am supposed to write where the structure is used will be called from a different function. Depending on the ID that gets passed in the memory needs to be allocated. For example, if ID is 1 that would be the first structure element. When 2 is passed in for ID, I need to increment the structure array and then allocate the memory for the members of this structure ID based on the size of the elements that is passed in.

6. So instead of using literal values like 5, 10, or 20, use variables instead.
Code:
`test *data = malloc(sizeof(test) * ID);`