Pointers in C

  • + 0 comments
    #include <stdio.h>
    
    void update(int *a,int *b) {
        *a = *a+*b;
        *b = abs(*a-*b-*b);
        //The extra *b is because *a value is changed above by adding *b
        //So to equalize the effect we subtract *b
    }
    
    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;
    }