avr39ripe

PV024PointersBasics

Nov 19th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int max(int a, int b)
  4. {
  5.     static int flag{};
  6.  
  7.     return a > b ? a : b;
  8. }
  9.  
  10. int main()
  11. {
  12.     int numI{ 42 };
  13.     float numF{ 42.0 };
  14.  
  15.  
  16.     for (int i{ 0 }; i < 4; ++i)
  17.     {
  18.         std::cout << "numI[" << i << "]" << (int)((uint8_t*)&numI)[i] << "\n";
  19.     }
  20.  
  21.     for (int i{ 0 }; i < 4; ++i)
  22.     {
  23.         std::cout << "numF[" << i << "]" << (int)((uint8_t*)&numF)[i] << "\n";
  24.     }
  25.     //int num{ 42 };
  26.     //int otherNum{ 32 };
  27.  
  28.     //float temp{ 42.0 };
  29.  
  30.     //int* ptr{ &num };
  31.     //float* ptrFl{ &temp };
  32.  
  33.     //char symb{ 'A' };
  34.     //char* ptrCh{ &symb };
  35.  
  36.     //std::cout << "Value of *ptr = " << *ptr << '\n'; //42
  37.     //ptr = (int*)&symb;
  38.  
  39.     //std::cout << "Value of ptr = " << ptr << '\n'; //XX the same!!
  40.     //std::cout << "Value of ptrCh = " << (int*)ptrCh << '\n';//XX the same!!
  41.  
  42.     //std::cout << "Value of *ptr = " << *ptr << '\n'; //42???
  43.     //std::cout << "Value of *ptrCh = " << *ptrCh << '\n'; // 42
  44.  
  45.     //return 0;
  46.  
  47.     /*std::cout << "Enter some number";
  48.     std::cin >> *ptr;
  49.     std::cout << "Value of num = " << *ptr << '\n';
  50.     std::cout << "Value of num = " << num << '\n';
  51.  
  52.     *ptr += 10;
  53.     std::cout << "Value of num = " << *ptr << '\n';
  54.     std::cout << "Value of num = " << num << '\n';
  55.  
  56.     ptr = &otherNum;
  57.  
  58.     std::cout << "Enter some number";
  59.     std::cin >> *ptr;
  60.     std::cout << "Value of num = " << *ptr << '\n';
  61.     std::cout << "Value of num = " << num << '\n';
  62.  
  63.     *ptr += 10;
  64.     std::cout << "Value of num = " << *ptr << '\n';
  65.     std::cout << "Value of num = " << num << '\n';*/
  66.  
  67.  
  68.     //int x{ 42 };
  69.     //int y{ 65 };
  70.  
  71.     //bool flag{ true };
  72.     //const int arrSize{ 5 };
  73.     //char arr[arrSize];
  74.     //double number{ 333.33 };
  75.  
  76.     //int* ptrI{&x};
  77.     //std::cout << "Addr of x is " << &x << " ptrI = " << ptrI << " *ptrI = " << *ptrI << '\n';
  78.     //ptrI = &y;
  79.     //*ptrI = 456;
  80.     //std::cout << *ptrI << '\n';
  81.  
  82.     //std::cout << "Addr of x is " << &x << " ptrI = " << ptrI << " *ptrI = " << *ptrI << '\n';
  83.     //std::cout << "Addr of y is " << &y << " ptrI = " << ptrI << " *ptrI = " << *ptrI << '\n';
  84.  
  85.     //return 0;
  86.     //bool* ptrB{ &flag };
  87.     //const int* ptrCI{ &arrSize };
  88.     //double* ptrD{ &number };
  89.  
  90.     //*ptrI = 333;
  91.     //
  92.     //std::cout << " x = " << x << '\n';
  93.  
  94.     //std::cout <<"Addr of x is " << &x << " ptrI = " << ptrI << " *ptrI = " << *ptrI << '\n';
  95.     ////std::cout << "Addr of flag is " << &flag << " ptrB = " << ptrB << " *ptrB = " << *ptrB << '\n';
  96.     /////std::cout << "Addr of arrSize is " << &arrSize << " ptrCI = " << ptrCI << " *ptrCI = " << *ptrCI << '\n';
  97.     ////std::cout << "Addr of number is " << &number << " ptrB = " << ptrB << " *ptrB = " << *ptrB << '\n';
  98.  
  99.     return 0;
  100. }
  101.  
  102.  
Advertisement
Add Comment
Please, Sign In to add comment