Jump to content

Nested function

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 66.46.157.82 (talk) at 15:39, 17 December 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A nested function is a function which can only be called from the parent function. That is, the scope of the nested function is limited to the current function only. For instance, assuming that C supports nested functions (which it does not):

void foo() {

void bar() {
 /* do something */
};
bar();

}

In this case Italic textbarItalic text is a nested function for foo and can only be called from foo.

Nested functions are useful for creating code blocks that must remain logically seperate but are only useful for a specific function as opposed to the entire module or program.