Advertisement
pmcgee

C++ Fundamentals

Jan 10th, 2020
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. // Type your code here, or load an example.  --->>>  Godbolt.org  // Compiler Explorer
  2. #include <iostream>
  3.  
  4. int cppbasics() {
  5. // ---------------  
  6. // What is a pointer / reference ...  
  7.        int  a = 3;  
  8.        int& b = a;
  9.        int* p = &a;
  10.   long int  q = (long int) &b;
  11.  
  12.   std::cout << a << " " << b << " " << p << " 0x" << std::hex << q;
  13.  
  14. // ---------------  
  15. // What is the arrow operator ...    
  16.  
  17.   struct Test { int c;
  18.                 Test() {c=0;};    //constructor
  19.               } b;
  20.   Test*  e = &b;
  21.   int    d;
  22.  
  23.   d   = (&b)->c;  std::cout << " d " << d;
  24.   d   =    e->c;  std::cout << " d " << d;
  25.   d   = (*e) .c;  std::cout << " d " << d;
  26.  
  27. // ---------------  
  28.   return 0;
  29. }
  30.  
  31. int main() {
  32.     cppbasics();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement