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.
- Prepare
- C++
- Introduction
- Pointer
- Discussions
Pointer
Pointer
Sort by
recency
|
1144 Discussions
|
Please Login in order to post a comment
void update(int *a,int *b) { int sum= (*a)+(*b); int diff= abs((*a)-(*b));
(*a)=sum; (*b)=diff; } this may help :)
Hey, this is my code. Insights would be appreciated. Happy learning!
Using Ternary Operator
`Hey guys :
include
void update(int *a,int *b) { // Complete this function
int sum = *a + *b; int sub = abs(*a - *b);
} `
Simplest solution is below,
include
using namespace std;
void update(int *pa,int *pb){ int temp = *pa; *pa = *pa + *pb; *pb = temp > *pb ? temp - *pb : *pb-temp; }
int main(){ int a,b; cout <<"Enter a & b: "; cin >>a>>b; update(&a,&b); cout <<"sum: "<