Pointers in C HackerRank Solution

Pointers in C HackerRank Problem Solution
Pointers in C HackerRank Problem Solution

In this Pointers in C  HackerRank Solution, we will learn to implement the basic functionalities of pointers in C. A pointer in C is a way to share a memory address among different contexts (primarily functions). They are primarily used whenever a function needs to modify the content of a variable that it does not own.


*pa store the address of a , *pb store the address of b. In pa, store the value of a which is given by user and similarly pb store a value of b. calling the function update by passing the argument of value of pa and pb. because *pa and *pb is pointer then the function update (int *a, int *b) called. the prototype of the function update is void update(int *, int *); take variable one for summation i.e. max and another one for difference i.e. diff. max=*a+*b; *a means Value at Address , similarly for *b . then add both the values. now for difference, diff=abs(*a-*b); abs is a function of absolute that dissolve the negative sign which in math.h header file, i used it because of our output , need only positive difference so i used it. You can not used if it not needed. Hope I will able to explain you for your better understand.

2 lines Solution – Solution 2

void update(int *a,int *b) {
    // Complete this function

Solve original Problem on HackerRank here. Checkout more HackerRank Problems