Hackerrank C++ ---- Pointer

#include <stdio.h>
#include<stdlib.h>
void update(int *a,int *b) 
{
    // Complete this function    
    int tmp;
    tmp=*a+*b;
    *b=abs(*a-*b);
    *a=tmp;
}

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;
}

Comments

Popular posts from this blog

Infosys - Monster RPG GAME Sample Question Solution

Hackerrank -- C++ - Variable Sized Array Solution