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.
Why is it necessary in this case to redeclare *a as (temp) in order to let the abs() do it's job ?? Bcz I tried the following cood but it didn't work !!
include
include
include
using namespace std ;
void update(int *a, int *b) {
*a = *a + *b ;
*b = abs(*a-(*b)) ;
}
int main() {
int a, b ;
int *pa = &a, *pb = &b ;
cin >> a ;
cin >> b ;
update(pa, pb);
cout << a << endl ;
cout << b << endl ;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pointer
You are viewing a single comment's thread. Return to all comments →
Why is it necessary in this case to redeclare *a as (temp) in order to let the abs() do it's job ?? Bcz I tried the following cood but it didn't work !!
include
include
include
using namespace std ;
void update(int *a, int *b) { *a = *a + *b ; *b = abs(*a-(*b)) ; } int main() { int a, b ; int *pa = &a, *pb = &b ;
cout << a << endl ; cout << b << endl ;
}