1. ## about dynamic memory arrays

I am trying to switch values stored inside arrays placed in heap. Program works like that.

Code:
```
void switchValue(int *a, int*b){

int temp[]={1,2,3,4};
for(int i=0; i<4; i++){
temp[i]=a[i];
a[i]=b[i];
b[i]=temp[i];
}
}
int main()
{
int *A=(int*)calloc(4,sizeof(int));
int *B=(int*)calloc(4,sizeof(int));

A[0]=1, A[1]=2, A[2]=3, A[3]=4;
B[0]=9, B[1]=8, B[2]=7, B[3]=6;

switchValue(A,B);

for(int i=0;i<4;i++){
printf("%d ",A[i]);
}

printf("\n");

for(int i=0;i<4;i++){
printf("%d ",B[i]);
}}```

Compiler doesn't let me install my values like
Code:
`A[]={1,2,3,4}`
, no surprises. But what if I have 100 or 1000 values, I have to install my values like
Code:
`A[0]=1, A[1]=2..`
How can I store my values in heap easier?

Another question is when I create an array like int temp[4]; program dont stop working. I have to define values inside it(can see it in 3rd row of the code). I don't understand the problem.
Any help would be appreciated.
Thank you

2. Well if you have 100's or 1000's of numbers, your best bet is to read them from a file, so you can assign them to your allocated array using a loop.

> Another question is when I create an array like int temp[4];
Because that is 'initialisation', not 'assignment'.
You can initialise arrays as you have done here, but you can't declare an array and then later on assign the array elements en masse using a comma list.

Also, you only need int temp;
Re-use the same temp each time around the loop.

3. How can I store my values in heap easier?
If your arrays are a "fixed" size then you could avoid using malloc/calloc and just use a static qualified array instead.

Code:
`    static int A[] = {1, 2, 3, 4};`
Another question is when I create an array like int temp[4]; program dont stop working.
Why is temp an array instead of just a single instance?

4. Thank you very much for both answers. And yes, I should definitely use single and static int for this code.