Pointers

PHOTO EMBED

Sun Jan 09 2022 14:04:55 GMT+0000 (UTC)

Saved by @jarodnbuus #c++

#include <stdio.h>

void update(int *a,int *b) {
     
    
    int ans = *a; 
    *a = *a + *b;
    *b = ans - *b; 
    if (*b <0){
        *b = -(*b);
    }
    
    //printf("*pb %d\n", *pb);
    //printf("*a %d\n",*a);
    //printf("*b %d\n",*b);
    //printf("*pa %d\n",*pa);
    //printf("\n"); 
    //    
}

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

https://www.hackerrank.com/challenges/c-tutorial-pointer/problem?h_r=profile