File Scope of Variable :
- File Scope is also called Global Scope
- It can be used outside the function or a block
- It is visible in entire program
- Variables defined within Global scope is called as Global variables
Definition : Variable is said to have global scope / file scope if it is defined outside the function and whose visibility is entire program
Live Example :
#include<stdio.h> void message(); int num1 = 1; // Global void main() { int num1 = 6 ; printf("%d",num1); // Local variable is accessed message(); } void message() { printf("%d",num1); // Global variable is accessed }
Output :
- 6 1
Explanation :
- Program have two functions main and message
- As num1 declared in main is local to main , so it can be accessed from main
- But num1 is not defined in the function message , then global variable is accessed