Nested Function in C

Nested Function Definition :

Nesting happens when one or more functions are utilised inside another function in the C programming language. A function cannot be defined inside of another function in the C programming language (nested function is not supported by C language).

Function call by value in C

Nested Function in C:

Some programmers believe that the term “nested function” refers to the definition of a function inside another function.However, in practise, it is considered as lexical scoping rather than a nested function.

  • Lexical scoping is invalid in C because the compiler is unable to access or locate the inner function’s proper location in memory.
  • Since they cannot access local variables of the neighbouring blocks, nested function definitions can only access global variables of the container module.This is done so that the directory is not required for global variable lookups.
  • Similar to C, there are two layers of scopes: local and global (and beyond this, built-ins).Nesting functions are therefore only occasionally used.
  • In C, we see a compile-time error whenever we attempt to access nested functions.

Example :

 int my_fun() {
        printf("check_fun function");
int main() {
        printf("Main Function\n"); 

Output :

check_fun function
Main Function

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription