3/14/2016

HackerRank solution for Pointer In C++

Problem:- Pointer Hacker Rank Solution or Pointer hacker rank solution c++ orMulti Level Inheritance in java or Pointer solution or Pointer solution in C++ or Pointer hacker rank solution in Java or Pointer hacker rank solution c++ or Pointer hacker rank solution c++ or Pointer program in c or Pointer solution in C or Hacker Rank Solution For Pointer in C++ or Pointer in C++ or Hacker Rank solution for Pointer in C++.

Check This- Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.


Explanation:- We know about the pointer, as we know pointer holds the address of another variable. In this problem, we are passing the address of a variable not the value of the variable so anything changes into the value, affect the original value of the variable. If you want to practice in pinter there are many programs you can understand.


Submit your solution here:- Click here


Solution:-

#include <iostream>
using namespace std;

void update(int *a,int *b)
{
    int temp = *a;
    *a = *a + *b;
    *b = temp - *b;

    if(*b < 0)
{
        *b = -(*b);
    }
}

int main() 
{
    int a, b;
    int *pa = &a, *pb = &b;

    cin>>a>>b;
    update(pa, pb);
    cout<<a<<"\n"<<b;

    return 0;
}

Output:-

Hacker Rank solution for Pointer In C++

Hacker Rank solution for Pointer In C++


You May Also Like

1. C Program For Open A File (Or Open The Same Program Itself ) Itself Using File Handling

2. C Program For Compare Two String Using Pointer

3. C Program For Reverse A String Using Pointer

4. C++ Program To Print Address Of Pointer Of An Array Using Pointer

5. C++ Program For Swapping Two Number In Function Using Pointer

6. C++ Program To Average Of Array In Function Of Using Pointer

7. C++ Program To Read Infinite Number And Arrange Ascending Order Using Pointer

8. C++ Program To Find Number Is Even Or Odd Using Pointer


9. Hacker Rank solution for Virtual Functions

10. Hacker Rank solution for Birthday Cake Candles


No comments:

Post a Comment