-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointers.cpp
69 lines (65 loc) · 1.56 KB
/
pointers.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// adress
// #include <iostream>
// using namespace std;
// int main() {
// int x = 3;
// cout<<&x<<endl;
// // 0x61ff0c it is the adress of value x
// }
// #include <iostream>
// using namespace std;
// void swap(int& x,int&y) {
// int temp = x;
// x = y;
// y = temp;
// }
// int main() {
// int x = 12;
// int y = 20;
// swap(x,y);
// cout<<"Value of x after swap is: "<<x<<endl;
// cout<<"Value of y after swap is: "<<y;
// }
// pointers ==> Acess the value of the variable choose adress is in the pointers using dereference /* operator
// #include <iostream>
// using namespace std;
// int main() {
// int x = 3;
// int * ptr = &x;
// cout<<ptr<<endl;
// cout<<&x<<endl;
// cout<<*ptr<<endl; // star operator by using that pitch the value
// cout<<&ptr<<endl; // show the adress of the operator
// *ptr = 20;
// cout<<x<<endl;
// }
// swap value in pointers
// #include <iostream>
// using namespace std;
// void swap(int* a,int* b) {
// int temp = *a; // temp = 10
// *a = *b; // *a = 20
// *b = temp;
// }
// int main() {
// int x = 12;
// int y = 20;
// swap(&x,&y);
// cout<<"Value of x after swap is: "<<x<<endl;
// cout<<"Value of y after swap is: "<<y;
// }
// max function by using multiple return statement
#include <iostream>
using namespace std;
int maxValue(int a, int b){
if (a>b)
{
return a;
} else
{
return b;
}
}
int main() {
cout<<maxValue(10,20);
}