Does a static function need the static keyword for the prototype in C?

前端 未结 2 473
后悔当初
后悔当初 2020-12-23 19:21

My C programming book says that when I want to create a static function, I need to put the static keyword in front of the function definition. It doesn\'t mention a

2条回答
  •  天涯浪人
    2020-12-23 20:05

    yes, yes you do need to put static in front of the declaration.

    type this into ideone.com

    int add();
    int main(){
        printf("%d",add());
        return 0;
    }
    
    static int add(){
        return 1+1;
    }
    

    you get this result: http://ideone.com/VzZCiE

    now type this

    static int add();
    int main(){
        printf("%d",add());
        return 0;
    }
    
    static int add(){
        return 1+1;
    }
    

    you get this: http://ideone.com/sz8HVR

    boooom

提交回复
热议问题