Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pointers and references syntax
- int x = 5;
- int& y = x; // y == x
- y++; // y == 6 && x == 6
- int * z = &x; // z is address of x
- int * zz = &y; // z == zz && *z == *zz && *z == 6 && *z == x && *z == y
- (*zz)++; // x == 7 && *z == 7 etc.
- // References
- int x = 5, y = 10;
- int& z = x;
- z = y;
- ++y;
- // z == 10 && x == 10 && y == 11
- // Pointers are nullable
- int * x = NULL; // OK
- int& x = NULL; // does not compile
- // Const modifiers
- int * x0; // pointer to int
- ++x0; // OK
- ++(*x0); // OK
- const int * x1; // pointer to constant int
- int const * x2; // same thing
- ++x1; // OK
- ++(*x1) // FAIL
- int * const x3; // constant pointer to int
- ++x3; // FAIL
- ++(*x3); // OK
- const int * const x4; // constant pointer to constant int
- int const * const x5; // same thing
- ++x4; // FAIL
- ++(*x4); // FAIL
- const int const * xx; // should not compile
- int & x6; // reference to int
- const int & x7; // reference to constant int
- int & const x8; // this doesn't make sense, I'm not sure that it compiles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement