Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int mas[5] = {1, 2, 3, 8};
- const int *ptr1 = mas;
- const int (&ptr2)[5] = mas;
- std::cout << sizeof ptr1 <<std::endl; // 4 или 8 - зависит от битности системы
- std::cout << sizeof *ptr1 <<std::endl; // 4 (скорее всего)
- std::cout << sizeof ptr2 <<std::endl; // 20
- ptr1 = &mas[0];
- ptr1 = &mas[1];
- int i = 42;
- ptr1 = &i;
- *ptr1 = 100500;
- ptr2 = mas;
- const int *ptr = mas;
- const int (*ptr2)[5] = &mas;
- const int &r = mas[1]; //Ссылка на второй элемент массива mas;
- const int (&r2)[5] = mas;
- int mas[5] = {1, 2, 3, 8};
- const int *ptr = mas;
- int (*ptr2)[5] = &mas;
- const int &r = mas[1];
- const int (&r2)[5] = mas;
- cout << uintptr_t(ptr + 1) - uintptr_t(ptr) << " " << sizeof(int) << " " << sizeof(r) << endl;
- cout << uintptr_t(ptr2 + 1) - uintptr_t(ptr2) << " " << sizeof(mas) << " " << sizeof(r2) << endl;
- cout << sizeof(ptr) << " " << sizeof(*ptr) << " " << sizeof(ptr2) << " " << sizeof(*ptr2) << endl;
- mas[1] = 42; (*ptr2)[2] = 24;
- cout << r << " " << r2[2] << endl;
- ptr = &mas[3];
- cout << *ptr << endl;
- 4 4 4
- 20 20 20
- 8 4 8 20
- 42 24
- 8
Add Comment
Please, Sign In to add comment