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
, no surprises. But what if I have 100 or 1000 values, I have to install my values like
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