We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. C++
  3. Introduction
  4. Pointer

Pointer

Problem
Submissions
Leaderboard
Discussions
Editorial

A pointer in C++ is used to share a memory address among different contexts (primarily functions). They are used whenever a function needs to modify the content of a variable, but it does not have ownership.

In order to access the memory address of a variable, , prepend it with sign. For example, &val returns the memory address of .

This memory address is assigned to a pointer and can be shared among functions. For example, assigns the memory address of to pointer . To access the content of the memory pointed to, prepend the variable name with a *. For example, *p will return the value stored in and any modification to it will be performed on .

void increment(int *v) {
    (*v)++;
}

int main() {
    int a;
    scanf("%d", &a);
    increment(&a);
    printf("%d", a);
    return 0;
}  

Function Description

Complete the update function in the editor below.

update has the following parameters:

  • int *a: an integer
  • int *b: an integer

Returns

  • The function is declared with a void return type, so there is no value to return. Modify the values in memory so that contains their sum and contains their absoluted difference.

Input Format

Input will contain two integers, and , separated by a newline.

Sample Input

4
5

Sample Output

9
1

Explanation

Author

abhiranjan

Difficulty

Easy

Max Score

10

Submitted By

482055

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy