You can declare them as extern in header file and define them in a .c source file. But I've tried nonetheless to define a global variable in the following header lib.h: //lib.h int i; void add (); I got some interesting results when trying to use this header in C and in C++. The global variables will hold their value throughout the lifetime of your program. c global variable in header To enable the use of global variables in your model, select Enable global variables as function interfaces from Model Settings > Configuration Parameters > Simulation Target. Global variables in C - Codeforwin Static member variables The header is included by the one source file that defines the variable and by all the source files that reference the variable. The correct way of doing this is: Make glob_x extern in x.h, and declare the variable in only one of your.c files. But the preferable way is to pass the variable to the places where it's needed. I want this array to be global and be used anywhere in my program. Global variables are defined outside of all the functions, usually on top of the program. So the real significance of the static … This answer is not useful. Static data initialization in C/C++ headers – XILTI Lets have an example: we have an header file, which declare the static variable in the header file: /* * sample.h */ #ifndef __SAMPLE_H #define __SAMPLE_H /* static variable… It means that each .cpp file has its own copy of the variable. C Declare a variable, say ‘int glob_x’ in ‘x.h’. This tells the compiler to actually allocate an instance (memory) for the variable. Static variables # A Static variable is able to retain its value between different function calls. What are global variables in