I'm trying to change array's variables address by swapping the address, not the value. I have a function that swap the numbers in the array: a[0]=a[9] , a[9]=a[0], a1=a[8] , a[8]=a1, a[2]=a[7] , a[7]=a[2], ec`. If you look at the image, for example in the array arr[0] = 33, address is 00...E8. I want to swap it with the last number to be arr[0] = 10 with address of 00..0C. now I have arr[0] = 10, address 00...E8, i switched the value and not the address.
how can I implement this?
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
void invert(int arr[], int size)
{
int n;
int temp;
for (n = 0; n < size / 2; n++)
{
temp = arr[n];
arr[n] = arr[size - 1 - n];
arr[size - 1 - n] = temp;
}
printf("after invertion");
printf("\n");
for (n = 0; n < 10; n++)
{
printf(" %d ", arr[n]);
printf(" %p\n", &arr[n]);
}
}
void main()
{
int arr[10];
int i;
srand(time(NULL));
for (i = 0; i < 10; i++)
{
arr[i] = rand() % 50;
}
printf("before invertion");
printf("\n");
for (i = 0; i < 10; i++)
{
printf(" %d ", arr[i]);
printf(" %p\n", &arr[i]);
}
printf("\n");
invert(arr, 10);
}
