Pointers in C

  • + 0 comments

    Using abs() from stdlib

    #include <stdio.h>
    #include <stdlib.h>
    
    void update(int *a,int *b) {
        // Complete this function
        int aTemp = *a;
        int bTemp = *b;
        *a = aTemp + bTemp;
        *b = abs(aTemp - bTemp);
    }
    
    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;
    }