‘Extern’ storage class specifier
In this article, let’s understand ‘extern‘ keyword.
In C, the ‘extern‘ storage class specifier is used to declare a variable or function that is defined in another file or translation unit within the same program. It serves as a way to extend the visibility and accessibility of variables and functions across multiple files, allowing them to be used in a modular and organized manner.
We already used this extern keyword in our previous example. But let’s know some points about the extern keyword.
- ‘extern’ storage class specifier is used to access the global variable, which is defined outside the scope of a file.
- ‘extern’ storage class specifier can also be used during the function call, when the function is defined outside the scope of the file.
Here, in this case, mentioning the extern keyword is not compulsory. It is optional. As we saw in the previous example, extern is assumed when you try to call a function which is outside the scope of that file.
- The keyword ‘extern’ is relevant only when your project consists of multiple files, and you need to access a variable defined in one file from another file.
So, it makes sense only when you have multiple files. Otherwise, you need not use ‘extern.’
- ‘extern’ keyword is used to extend the visibility of a function or variable.
That’s about the ‘extern’ keyword.
Get Microcontroller Embedded C Programming Full Course Here
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1