2017-01-29 133 views
-8
void main() 
{ 
    int const *p=5; 
    cout<<++(*p); 
} 

這會做什麼?這是錯誤的,如果是這樣,爲什麼?請讓我明白。謝謝!這會做什麼? C++

+5

這將讓你downvotes居多。爲避免將來出現這種情況,您應該參考[參考](http://stackoverflow.com/tour)並閱讀[幫助頁面](http://stackoverflow.com/help)。這裏是[The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 –

+0

我做錯了什麼?我是新來的,請解釋一下!謝謝 – Occlet

+1

當你編譯這段代碼時,你的編譯器會說什麼? –

回答

2

這會做什麼?

該程序不合格,可能會拒絕編譯。如果編譯,行爲不是由標準規定的。

這是錯誤的,如果是這樣,爲什麼?

它是。因爲:

error: '::main' must return 'int' 
error: invalid conversion from 'int' to 'const int*' 
error: 'cout' was not declared in this scope 
error: increment of read-only location '* p'