Javatpoint Logo
Javatpoint Logo

Understanding the "extern" Keyword in C

By extern keyword, we mean external in C programming language. We will understand the extern keyword with a small example scenario where two variables must be accessed in two different files. In this case, the extern keyword comes handy. While defining a function or a variable in the C programming language, the memory is allocated for the variable, or the function declared.

It helps us extend the visibility of the functions and the variables in the C programming language; hence it is named as an external keyword in short read as an extern. Declaration of a variable or a function is no big deal, but allocating sufficient memory for them is a critical task, and the extern keyword is used in such problems.

Variables in C -1

Output:

b

Variables in C -2

Output:

221,231
221,332
221,433

Variables in C -3

Output:

Compiles without any error

Extern keyword

Output:

/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned one exit status

The below codes compile successfully and don't throw any errors when compiled.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA