I've seen many different ways of writing the address-of operator (&) and the indirection operator (*)
If I'm not mistaken it should be like this:
//examples
int var = 5;
int *pVar = var;
cout << var << endl; //this prints the value of var which is 5
cout << &var << endl; //this should print the memory address of var
cout << *&var << endl; //this should print the value at the memory address of var
cout << *pVar << endl; //this should print the value in whatever the pointer is pointing to
cout << &*var << endl; //I've heard that this would cancel the two out
What would happen if for example you wrote &var
as & var
with a space between the two? Common syntax I have seen: char* line = var;
, char * line = var;
, and char *line = var;
.