Find size of a function in C

后端 未结 9 1765
别跟我提以往
别跟我提以往 2020-12-10 16:37

I am learning function pointers,I understand that we can point to functions using function pointers.Then I assume that they stay in memory.Do they stay in stack or heap?Can

9条回答
  •  眼角桃花
    2020-12-10 17:11

    #include
    
    int main(){
        void demo();
        int demo2();
        void (*fun)();
        fun = demo;
        fun();
        printf("\n%lu", sizeof(demo));
        printf("\n%lu", sizeof(*fun));
        printf("\n%lu", sizeof(fun));
        printf("\n%lu", sizeof(demo2));
        return 0;
    }
    
    void demo(){
        printf("tired");    
    }
    
    int demo2(){
        printf("int type funciton\n");
        return 1;
    }
    

    hope you will get your answer, all function stored somewhere

    Here the output of the code

    above code's output

提交回复
热议问题