-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer.cpp
More file actions
33 lines (24 loc) · 674 Bytes
/
Copy pathpointer.cpp
File metadata and controls
33 lines (24 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**The function is declared with a void return type, so there is no value to return.
Modify the values in memory so that a contains their sum and b contains their absoluted difference.**/
//#include <stdio.h>
#include <iostream>
#include <cstdlib>
//#include <cmath>
void update(int &x, int &y){ //in C use *x,*y
//in c++,don't use raw pointers, use reference instead
int tmp{x+y};
y = std::abs(x-y);
x=tmp;
}
int main(){
int a,b;
int *pa = &a;
int *pb = &b;
std::cin>>a>>b;
//scanf("%d %d", &a, &b); //in C
update(*pa,*pb);
std::cout<<a<<std::endl;
std::cout<<b;
//printf("%d\n%d", a, b); //in C
return 0;
}