I want to reverse an array element using pointer But why i getting out-put as 4 3 3 4 when i give input 1 2 3 4
here my code
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int n, a[100], *ptr;
printf("enter array size: ");
scanf("%d",&n);
printf("enter array element: ");
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
ptr = &a[0];
int j=0;
int i = n-1;
while(j != n)
{
a[j] = *(ptr+i);
j++;
i--;
}
// for printing output
printf("\nin reverse: \n");
for(int k=0; k<n; k++)
{
printf("%d, ",a[k]);
}
return 0;
}
can anybody tell me what is the problem here ?