14
可能重複:
How does dereferencing of a function pointer happen?函數指針 - 自動提領
void myprint(char* x) {
printf("%s\n", x);
}
int main() {
char* s = "hello";
void (*test)(char*);
void (*test2)(char*);
test = myprint;
test2 = &myprint;
test(s);
(*test)(s);
test2(s);
(*test2)(s);
}
誰能向我解釋爲什麼所有上面的代碼是有效的? 「你好」打印四次。通過應用函數指針,它是否被隱式地拒絕了?基本上我想知道函數指針是如何實際存儲的,因爲上面有點混淆。
'(****** test)(s)'也是有效的:-) – sidyll
請參見前面的問題:http://stackoverflow.com/questions/2795575/how-does-dereferencing-of-a函數指針發生 –
函數和函數指針是特殊的,它們的處理與任何其他類型的指針都不一致。請參閱[如何解除函數指針的解除引用?](http://stackoverflow.com/q/2795575/2509)以及側邊欄中的其他問題。 – dmckee