How do I share a global variable between c files?

前端 未结 7 1123
一生所求
一生所求 2020-12-07 18:28

If i define a global variable in a .c file, how can i use the value of the same variable in another .c file?

file1.c

#incl         


        
7条回答
  •  攒了一身酷
    2020-12-07 19:13

    Use the extern keyword to declare the variable in the other .c file. E.g.:

    extern int counter;
    

    means that the actual storage is located in another file. It can be used for both variables and function prototypes.

提交回复
热议问题