valenki13

lesson_321_21

Oct 9th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // ф-я с аргументом по умолчанию
  6. int sum(int a, int b, int c = 0) {
  7.     return a + b + c;
  8. }
  9.  
  10. void task0() {
  11.     int d = 5;
  12.     double x = 17.5;
  13.     bool arr[]{ true, false, true, false };
  14.  
  15.     cout << &d << " " << &x << endl;
  16.     cout << arr << " " << &(arr[0]) << endl;
  17.     cout << sum << endl;
  18.  
  19.     double* px = &x, *py = &x;
  20.     int* pd = &d;
  21.     cout << px << " " << pd << endl;
  22.     bool* pArr = &(arr[0]);
  23.     cout << pArr << endl;
  24.  
  25.     cout << px << " " << *px << " "
  26.         << typeid(*px).name() << " "
  27.         << x << endl; // оп разъименования
  28.  
  29.     // *px - это l-value
  30.     *px = 55.123;
  31.     cout << px << " " << *px << " " << x << endl;
  32.  
  33.     double very_long_name_for_my_variable = 15.123;
  34.    
  35.     // Указатель, pointer
  36.     double* pVal;
  37.     pVal = &very_long_name_for_my_variable;
  38.     cout << *pVal << endl;
  39.  
  40.     // Ссылка, reference
  41.     double& Val = very_long_name_for_my_variable;
  42.     cout << Val << endl;
  43.     Val++;
  44.     cout << Val << endl;
  45. }
  46.  
  47. void pointers_array() {
  48.     int arr[]{ 8, 11, 2, 7, 9 };
  49.     int* px = arr;
  50.     int* py = &(arr[3]);
  51.    
  52.     int& my_fav = arr[0];
  53.     cout << *px << " " << my_fav << " " << px << endl;
  54.  
  55.     cout << px << " " << py << endl;
  56.     cout << px - py << endl;
  57.  
  58.     cout << px << " " << px + 1 << " " << *(px + 1) << endl;
  59. }
  60.  
  61. void showarr_by_pointers() {
  62.     int arr[]{ 1,2,3,5,7,9 };
  63.    
  64.     for (int k = 0; k < size(arr); k++) {
  65.         cout << *(arr + k) << ", ";
  66.     }
  67.     cout << endl;
  68.  
  69.  
  70.    
  71.  
  72.     for (int* pk = arr; pk != arr + size(arr); pk++) {
  73.         cout << *pk << ", ";
  74.     }
  75.     cout << endl;
  76. }
  77.  
  78.  
  79. int main() {
  80.     //task0();
  81.     //pointers_array();
  82.     showarr_by_pointers();
  83. }
Add Comment
Please, Sign In to add comment