Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char glob = 'G';
- int sum(int a, int b) {
- return a + b;
- }
- void test_address() {
- int d = 7;
- double x = 3.14;
- bool arr[]{ true, false, true, false };
- cout << &d << " " << &x << " "
- << arr << " " << sum << endl;
- cout << &(arr[0]) << endl;
- cout << &(arr[3]) << endl;
- // Взять адрес от rvalue - нельзя
- //cout << &(3) << &(sum(1, 2)) << &(x + 1);
- int* pd = &d;
- cout << "int pointer: ";
- cout << pd << " " << &d << endl;
- double* px = &x;
- cout << "double pointer: ";
- cout << px << " " << &x << endl;
- cout << "get value: ";
- cout << d << " " << *pd << endl;
- bool* pArr = arr;
- bool* pArr2 = &(arr[0]);
- cout << *pArr << endl;
- cout << *(pArr + 1) << " " << arr[1] << endl;
- }
- void task_pointers_array() {
- int arr[]{ 3,4,6,4,2,2 };
- for (int k = 0; k < size(arr); k++) {
- cout << *(arr + k) << " "
- << arr + k << endl;
- }
- for (int* pk = arr; pk != arr + size(arr); pk++) {
- cout << *pk << " ";
- }
- cout << endl;
- // arr[k] ~ *(arr + k)
- /*
- int k = 0;
- for (;;) {
- k++;
- if (k > 5)
- break;
- }
- */
- cout << endl;
- }
- void task2() {
- int x = 15;
- int y = 19;
- int* px;
- px = &x;
- int* py = &y;
- cout << x << " " << px << endl;
- cout << y << " " << py << endl;
- // суммировать адреса безсмысленно
- // cout << px + py << endl;
- // cout << px * py << endl;
- // cout << px / py << endl
- cout << px - py << endl;
- *px = 18; // *px - это как бы x - lvalue
- cout << x << endl;
- px = py;
- cout << *px << " "
- << *py << " "
- << y << endl;
- }
- int main() {
- //test_address();
- //task_pointers_array();
- task2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment