ampersand (&) at the end of variable etc

const date& being accepted by the method date_ok means that date_ok takes a reference of type const date. It works similar to pointers, except that the syntax is slightly more .. sugary

in your example, int* Y = &x makes Y a pointer of type int * and then assigns it the address of x. And when I would like to change the value of “whatever it is at the address pointed by Y” I say *Y = 200;

so,

int x = 300;
int *Y = &x;
*Y = 200; // now x = 200
cout << x; // prints 200

Instead now I use a reference

int x = 300;
int& Y = x;
Y = 200; // now x = 200
cout << x; // prints 200

Leave a Comment

tech