![]() |
VOOZH | about |
An inline variable in C++ is a variable that is declared using an inline specifier. It is an exception to one definition having multiple definitions across various translation units. Inline variables have an external linkage when not declared as static.
inline data_type variable_name = initial_value;
Note: If there are multiple definitions of inline variable, the compiler picks one of the definition when required.
It is very easy to use inline variables in C++. It is just a three-step process to declare and use inline variables in our program:
We can easily declare a variable as inline by using the keyword inline before the normal declaration and we can also assign value to the variable with the help of the regular assignment operator.
head.hpp
An inline variable defined inside a header file can be accessed by importing that header file using #include preprocessor directive.
source.cpp
Output
10
The following are some main properties of Inline Variables:
Example
Output
10