# One question about function pointer

**URL:** <https://forum.modular.com/t/one-question-about-function-pointer/3096>\
**Category:** Mojo\
**Created:** [May 19, 2026, 11:52pm UTC](https://forum.modular.com/t/one-question-about-function-pointer/3096 "2026-05-19T23:52:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertD](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@RobertD](https://forum.modular.com/u/RobertD)\
**Post date:** [May 19, 2026, 11:52pm UTC](https://forum.modular.com/t/one-question-about-function-pointer/3096/1 "2026-05-19T23:52:09Z")

</div>

Hello,  
I’m new one on Mojo.  
How to pass one function pointer(address or name) as a parameter in another function?

When I checked doc, only an example to show pass class method as function parameter.  
How about pure function ?

---

<div class="post-metadata">

**Author:** ![samufi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@samufi](https://forum.modular.com/u/samufi)\
**Post date:** [May 20, 2026, 5:02am UTC](https://forum.modular.com/t/one-question-about-function-pointer/3096/2 "2026-05-20T05:02:38Z")

</div>

Hi @RobertD,  
A standalone function should be passable in the same way as a struct method. Would you like to prove an example of what you tried and what has not worked out?

---

<div class="post-metadata">

**Author:** ![RobertD](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@RobertD](https://forum.modular.com/u/RobertD)\
**Post date:** [May 21, 2026, 6:36am UTC](https://forum.modular.com/t/one-question-about-function-pointer/3096/3 "2026-05-21T06:36:32Z")

</div>

Hello Samufi,  
Thanks for your reply.

For example:  
def add(val\_1: Int, val\_2: Int) → Int:  
return vaL\_1 + val\_2

def sub(val\_1: Int, val\_2: Int) → Int:  
return vaL\_1 - val\_2

I want to have a function oper, it can be used as below:  
oper(add, 12, 23)  
oper(sub, 35, 12)

How to declare the function of oper is Mojo?  
In c, it might be like below:  
int oper(int (\*f)(int, int), int val\_1, int val\_2) {  
return f(val\_1, val\_2);  
}

---

<div class="post-metadata">

**Author:** ![samufi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@samufi](https://forum.modular.com/u/samufi)\
**Post date:** [May 21, 2026, 8:33pm UTC](https://forum.modular.com/t/one-question-about-function-pointer/3096/4 "2026-05-21T20:33:49Z")

</div>

For a detailed description of that, please have a look here: [Mojo Closures 2026](https://forum.modular.com/t/mojo-closures-2026/3013)

In your case, you can pass the function as a parameter (rather than an argument):

```mojo
def oper[f: def(Int, Int) thin -> Int](val_1: Int, val_2: Int) -> Int:
   return f(val_1, val_2)

```

One hint: on the Mojo Discord, there is an AI bot channel where you can find answers to such questions quite quickly.
