Nested function in C

前端 未结 9 1677
眼角桃花
眼角桃花 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 13:05

    No you can't have a nested function in C. The closest you can come is to declare a function inside the definition of another function. The definition of that function has to appear outside of any other function body, though.

    E.g.

    void f(void)
    {
        // Declare a function called g
        void g(void);
    
        // Call g
        g();
    }
    
    // Definition of g
    void g(void)
    {
    }
    

提交回复
热议问题