Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
HackerRank pointers in c problem solution

HackerRank Pointers in C solution

YASH PAL, 12 July 202416 June 2025

HackerRank Pointers in C problem solution – In this tutorial, we will solve the HackerRank Pointer in C problem or write a program for this problem. in this challenge, we need to write a function that will receive two integer pointers a and b. all we just need is to set the value of a to the sum of a and b, and b to their absolute difference.

Using this problem set we are going to learn about the implementation and basic functionalities of pointers in c programming. pointers are always a useful functionality in c because they share the address as a value.

What is so special about pointer?

A pointer always used to hold the address of any other variable. so we don’t need to remember the value of any variable.

Solutions Explained in Video

HackerRank Pointers in C problem solution
HackerRank pointers in c problem solution
HackerRank Pointers in C solution

HackerRank Pointers in c solution.

#include <stdio.h>

void update(int *a,int *b) {
    // Complete this function 
    *a=*a+*b;
    *b=abs(*a-(2**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;
}

Explanation

In the above program first, we declared a main() function. inside the main function, we have declared two integer variables a and b. after that we have declared a pointer pa and assigned the address of variable a as the value of pointer pa. and the same for the pointer pb.

After that using the scanf() function we read the two values from the input string and assigned them to variables a and b. after that we called the update() function with two input arguments of type pointer pa and pb.

What is inside the update() function?

In the update function, we just assigned the sum of values a and b to *a and then we calculated the absolute difference value to pointer b.

Second solution

#include <stdio.h>
#include <stdlib.h>

void update(int *a,int *b) {
    // Complete this function
    int t1, t2;
    t1 = *a + *b;
    t2 = abs(*a - *b);
    *a = t1;
    *b = t2;
}

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

Next problem solution – HackerRank Conditional Statements in C solution

C Solutions coding problems solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes