>>3
Ignoring the "static" solution (not a real one), you could write this in 2 main ways:
1) Unportable: malloc a buffer, and write the function code to it, insert n's value in the function code. Not hard to do, but not portable.
2) Portable: make a FUNCALL-like macro, which calls a function with a context struct or value cell array, and have the function use the values in the struct (in this case, the value of n).
In the case 2, a function is either a piece of code or a structure which contains the address of a real function and an array or structure of values closed over (or pointers to them). A funcall function or macro can call the real function or the encapsulated structure (containing the real function and closed over values). This is how most Lisps do it, but it's done behind the scenes, so you don't really need to know how closures are implemented.