Pointers in C

    
        
        #include <stdio.h>

        void update(int *a, int *b) {
            int sum = *a + *b;
            int diff = *a - *b;
        
            *a = sum;
            *b = diff > 0 ? diff : -diff;
        }
        
        int main() {
            int a, b;
            scanf("%d %d", &a, &b);
        
            update(&a, &b);
        
            printf("%d\n%d\n", a, b);
        
            return 0;
        }
        
        
        
    

Let's go through the solution step by step:

We include the header file to use the standard input/output functions.

We define a function called update that takes two integer pointers a and b as parameters.

Inside the update function, we declare two integer variables sum and diff to store the sum and difference of the values pointed by a and b.

We use the dereference operator (*) to access the values pointed by a and b and perform the necessary calculations.

We update the value pointed by a with the sum by assigning sum to *a.

We update the value pointed by b with the absolute difference by assigning diff to *b after checking if diff is negative. If diff is negative, we convert it to a positive value using the negation operator (-).

In the main() function, we declare two integers a and b to store the input values.

We use the scanf() function to read input from the user and store it in the variables a and b.

We call the update function with the addresses of a and b by passing &a and &b as arguments.

We use the printf() function to print the updated values of a and b.

By providing the expected input and executing the code, you should see the desired output according to the problem statement on HackerRank.