Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int summ(int a, int b) {
- return a + b;
- }
- void test_reference() {
- int very_long_name = 18;
- int *pv = &very_long_name;
- int &ref = very_long_name;
- cout << very_long_name << " "
- << *pv << " " << ref << endl;
- ++(*pv);
- cout << very_long_name << " "
- << *pv << " " << ref << endl;
- cout << &ref << " " << pv << " "
- << &very_long_name << endl;
- int y = 222;
- ref = y;
- cout << very_long_name << " "
- << *pv << " " << ref << endl;
- int (*ref2)(int, int) = summ;
- cout << ref2(13, 344) << endl;
- int arr[]{ 3,4,5,6,7,8,9 };
- int& favorite = arr[4];
- }
- void task1() {
- int x = 4, y = 3;
- int* px = &x, * py = &y;
- cout << "max: " <<
- ((*px > *py)? *px : *py);
- }
- void task_pasport() {
- int index[4]{ 6,0,2,1 };
- int number[6]{ 7,3,2,7,7,7 };
- int* pas[]{ index, number };
- cout << pas[0][3] << endl;
- cout << pas[1][2] << endl;
- for (int k = 0; k < 10; k++) {
- cout << k % 2 << " ";
- }
- // pas[0][1];
- }
- // BAD
- void my_swap1(int a, int b) {
- int temp = a;
- a = b;
- b = temp;
- cout << "In: ";
- cout << a << " " << b << endl;
- }
- // BAD
- void my_swap2(int *pa, int *pb) {
- int* ptemp = pa;
- pa = pb;
- pb = ptemp;
- cout << "In: ";
- cout << *pa << " " << *pb << endl;
- }
- void my_swap3(int *pa, int *pb) {
- int temp = *pa;
- *pa = *pb;
- *pb = temp;
- cout << "In: ";
- cout << *pa << " " << *pb << endl;
- }
- void my_swap(int &a, int &b) {
- int temp = a;
- a = b;
- b = temp;
- cout << "In: ";
- cout << a << " " << b << endl;
- }
- void test_swap() {
- int x = 6;
- int y = 4;
- my_swap(x, y);
- //my_swap3(&x, &y);
- cout << "Out: ";
- cout << x << " " << y << endl;
- // Output: 4 6
- }
- int main(){
- //test_reference();
- //task1();
- //task_pasport();
- //test_swap();
- }
Advertisement
Add Comment
Please, Sign In to add comment