declaration of variables with same name as global,local and static

前端 未结 5 1550
北海茫月
北海茫月 2020-12-30 17:07

I have the following code snippet and I have to analyse what the output will be:

#include 

  void f(int d);

  int a = 1, b = 2, c = 3, d = 4         


        
5条回答
  •  忘掉有多难
    2020-12-30 17:27

    int a = 1, b = 2, c = 3, d = 4; ---> Global variables

    int main(){
        int a = 5, c = 6;         ---> Shadows the global `a` and `c`
    

    ....

    void f(int d){
        static int a = 0;         ---> local static variable visible only inside `f`
    

    ...

提交回复
热议问题