C Scope Rules

Scope defines the region of visibility or availability for a variable, out of which we can not reference that variable. There are two main kinds of scope.

  • global
  • local

Global Variable

Global variables can be accessed at any point throughout the program, and can be used in any function. There is single copy of the global variable is available.Global variables are defined outside of all the functions, usually on top of the program.

Local Variable

Variable declared inside a function or block of code are called local variables. They can be accessed only inside that function or block of code. Local variables are not available to outside function.

Example Program:

Note :- A program can have same name for local and global variables but local variable overrides the value.