2011-03-04 63 views

回答

3

沒有任何索引的數組名稱本身就是一個指針。

int a[10]; 
printf("%d\n",*a); // will print first value 
printf("%d\n",*(a+1)); // will print second value 
+0

不,這不是,但它自動轉換到一個。這個問題被標記爲C++,C++具有模板,並且它在替換一個時很重要。 – 2011-03-04 10:28:36

+0

'sizeof array'是數組的大小,而不是指針的大小。 – fredoverflow 2011-03-04 10:35:08

8

不,但它可以衰減到一個指針,只要你需要它。

void foo1(char * c) { 
} 


int main() { 
    char Foo[32]; 
    foo1(Foo); // Foo decays to a pointer 
    char * s = Foo; // Foo decays to a pointer which is assigned to s 
}