Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // ф-я с аргументом по умолчанию
- int sum(int a, int b, int c = 0) {
- return a + b + c;
- }
- void task0() {
- int d = 5;
- double x = 17.5;
- bool arr[]{ true, false, true, false };
- cout << &d << " " << &x << endl;
- cout << arr << " " << &(arr[0]) << endl;
- cout << sum << endl;
- double* px = &x, *py = &x;
- int* pd = &d;
- cout << px << " " << pd << endl;
- bool* pArr = &(arr[0]);
- cout << pArr << endl;
- cout << px << " " << *px << " "
- << typeid(*px).name() << " "
- << x << endl; // оп разъименования
- // *px - это l-value
- *px = 55.123;
- cout << px << " " << *px << " " << x << endl;
- double very_long_name_for_my_variable = 15.123;
- // Указатель, pointer
- double* pVal;
- pVal = &very_long_name_for_my_variable;
- cout << *pVal << endl;
- // Ссылка, reference
- double& Val = very_long_name_for_my_variable;
- cout << Val << endl;
- Val++;
- cout << Val << endl;
- }
- void pointers_array() {
- int arr[]{ 8, 11, 2, 7, 9 };
- int* px = arr;
- int* py = &(arr[3]);
- int& my_fav = arr[0];
- cout << *px << " " << my_fav << " " << px << endl;
- cout << px << " " << py << endl;
- cout << px - py << endl;
- cout << px << " " << px + 1 << " " << *(px + 1) << endl;
- }
- void showarr_by_pointers() {
- int arr[]{ 1,2,3,5,7,9 };
- for (int k = 0; k < size(arr); k++) {
- cout << *(arr + k) << ", ";
- }
- cout << endl;
- for (int* pk = arr; pk != arr + size(arr); pk++) {
- cout << *pk << ", ";
- }
- cout << endl;
- }
- int main() {
- //task0();
- //pointers_array();
- showarr_by_pointers();
- }
Advertisement
Add Comment
Please, Sign In to add comment