Nested function in C

前端 未结 9 1663
眼角桃花
眼角桃花 2020-11-22 12:24

Can we have a nested function in C? What is the use of nested functions? If they exist in C does their implementation differ from compiler to compiler?

9条回答
  •  攒了一身酷
    2020-11-22 12:44

    To answer your second question, there are languages that allow defining nested functions (a list can be found here: nested-functions-language-list-wikipedia).

    In JavaScript, which is one of the most famous of those languages, one may of nested functions (which are called closures) are:

    • To create class methods in constructors of objects.
    • To achieve the functionality of private class members along with setters and getters.
    • Not to pollute the global namespace (that goes for every language, of course).

    to name a few...

提交回复
热议问题