A good example of pointer code at Hacker Rank

A good example of pointer code at Hacker Rank:

#include <stdio.h>

void update(int *a,int *b) {
    // Complete this function    
 int sum;
 int abs;

 sum=*a+*b;


if(*a>*b){
    abs=*a-*b;
}
else{
    abs=*b-*a;
}

*a=sum;
*b=abs;

}

int main() {
    int a, b;
    int *pa = &a, *pb = &b;
    
    scanf("%d %d", &a, &b);
    update(pa, pb);
    printf("%d\n%d", a, b);

    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.