可能重複:
Confusion over C++ pointer and reference topic陣列/指針/參考混亂
假設我傳遞
int arr[10];
作爲參數的函數。
所有這些有效的函數原型?他們在爭論和原因方面有什麼不同?
這是我所知道的,到目前爲止(不知道正確與否)
1. void foo(int &arr); //a reference to an array, which preserve the size attribute?
2. void foo(int &arr[]); //the same (is it)?
3. void foo(int (&arr)[]); //I don't know
4. void foo(int &arr[10]); //is it the same as 2?
5. void foo(int (&arr)[10]);//no idea
6. void foo(int *arr); //a decayed pointer of the array, pointing to the first element of the array, losing the size attribute?
7. void foo(int *arr[]); //the same (is it?)
8. void foo(int (*arr)[]); //a pointer to an array, preserve the size
9. void foo(int *arr[10]); //the same as 7 (is it?)
10. void foo(int (*arr)[10]);//is the same as 8 (is it?)
11. void foo(int arr[]); //is the same as 6 (is it?)
12. void foo(int arr[10]); // is the same as 6 (is it?)
(我知道這需要一個詳盡的解釋,對不起,我完全糊塗了......)
你爲什麼還要打擾?這是功課嗎? – fredoverflow
檢查代碼中的右括號...你錯過了很多 –
我只是好奇,並沒有這不是一項功課 – Chin