C Global Variables

Last Updated Nov 1, 2015, 07:00:14 PM

Global variable in c is a variable with global scope, meaning it can be visible and accessible throughout the program.

Global variables in c can be accessed throughout the program and changes made to global variable persist. Global variables have the lifetime of the function call. The memory allocation for global variables be dynamically generated

Global Variable Example in C

If a global variable and local variable are declared with the same name in the same function, then the local variable will mask that global variable and prevents its normal behavior as a global

Few Important Points About Global Variables
  • They can be accessed from anywhere
  • The behavior is unpredectible
  • The lifetime of global variable is throughout the program
  • Global variables are declared outside the main() and other functions.
Productivity Tip!

It is highly recommended not to use global variables too often, and be careful with its behavior as it is unpredictable behavior

Example Try It Now

Other Variable Topics you might want to learn

Global Variables in C

Static Variabls in C

Difference between Static and Global Variables- StackOverFlow