我见过许多不同的写地址运算符 (&) 和间接运算符 (*) 的方法
如果我没记错的话应该是这样的:
//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
例如,如果您在两者之间写一个空格,会发生&var
什么& var
?我见过的常见语法:char* line = var;
, char * line = var;
, 和char *line = var;
.