I think, since the pointer used is of type int, you assume that you need to multiply i by 4, because depending on the compiler, int is 4 bytes. I think if you really only care about the exit, then you can do it the way you did with the reverse iteration.
What you need to do has already been mentioned by others, so I will give you my solution for actually replacing the pointer memory and you can choose from these solutions:
#include<stdio.h> #define N 10 int array[N]; //Global variable int main(void) { int j; int i; printf("Enter 10 numbers: "); for (i=0; i<N; i++) { scanf("%d", (array + i)); } for (left = 0; left < N / 2; left++) { int right = N - left - 1; int temporary = array[left]; array[left] = array[right]; array[right] = temporary; } for (i=0; i<N; i++) { printf("%d", (array + i)); } return 0; }
I programmed for algorithmic contests so you can trust me.
source share