1
我見過寫地址的運營商(&)和間接運算符(*)什麼是地址(&)和間接運算符的正確格式
的許多不同的方式如果我不在錯就應該是這樣的:例如,如果你在兩者之間的空間中寫道&var
爲& var
//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
會發生什麼?我見過的通用語法:char* line = var;
,char * line = var;
和char *line = var;
。
您是否嘗試過這一點? – aschepler
相關(在C中:http://stackoverflow.com/a/30423656/335858) – dasblinkenlight
在這個區域中,只有*空白符號用於區分令牌。例如,如果你有'char const * foo',你需要在'char'和'const'之間留空格(以防止它被視爲一個單獨的標記'charconst'),但其餘部分是無關緊要的 - 你可以根據需要在'*'的每一邊刪除或插入儘可能多的空白,並且它的含義也沒有區別(同樣用'&')。對於使用何種空白來最大化可讀性有廣泛的分歧。 –