Right Shift Elements

Given an array from the user the task is to right shift array all elements by one place using pointers.

Example:

Consider an array of size 5.

26497

Right shifted array.

72649

Note: Here the last element is brought to first position of the array.

C
#include <stdio.h>
int main()
{
    int n=0,temp=0;
    printf("Enter the size of array: ");
    scanf("%d",&n);
    int ar[n];
    int *p=ar;
    printf("Enter the array elements:\n");
    for(int i=0;i<n;i++)
    {
        scanf("%d",p);
        p++;
    }
    p=ar+(n-1);
    temp=*p;
    for(int i=0;i<n-1;i++)
    {
        *p=*(p-1);
        p--;
    }
    *p=temp;
    printf("Right shifted array: ");
    for(int i=0;i<n;i++)
    {
        printf("%d ",*p);
        p++;
    }
    return 0;
}
C