WAP to swap values of 3 variables using pointer

Write a program to swap (rotate) values of 3 variables using pointer

#include<stdio.h>

void ratate(int *a, int *b, int *c){
       int temp,*tempPtr=&temp;
       *tempPtr = *a;
       *a = *b;
       *b = *c;
       *c = *tempPtr;
}

int main() {
       int a,b,c;
       printf("Enter three numbers: ");
       scanf("%d%d%d",&a,&b,&c);
       ratate(&a,&b,&c);
       printf("a = %d\nb = %d\nc = %d",a,b,c);
       return 0;
}

Output

Enter three numbers: 1
2
3
a = 2
b = 3
c = 1

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments