# function pointer

宣告函式時同樣需要一些記憶體 addr 來存, 簡單來說, 用存取指標來call function

**用途 :**

可以把function call 當引數傳遞

**宣告: (記法 - 把 function name 換成 記憶體位址)**

func\_return\_type (\*pointer\_name)(arguments);

**函式指標陣列 :**

function\_return\_type (\*pointer\_name\[array\_length])(argument);

**ex: (interview-c/pointer/func\_ptr/sort/enhance)**

`int (*compare[10])(int, int); //可以儲存十個sort function的位址`

**比較好的寫法 - typedef**

`typedef int (*CMP)(int, int);`

`CMP compare[10];`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fashaun.gitbook.io/dev-c/pointer/function-pointer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
