Article

Chapter 11 (difference-between-local-and-Global-Variable)


Difference between Local Variable and Global Variable:-

1. Local Variable:

variable declared inside a function and having no scope outside the function.

Example:-

void fun()

{

int n=10; //-------------Local Variable

}

void main()

{

fun();

printf("%d",n); //------------------Error undefined symbol n

}

2. Global variable:

It is the variable of the program and can be used anywhere in the existing programme.

Example:-

int n;   //-------Global Variable

void fun()

{

n=10;

}

void main()

{

fun();

printf("%d",n);

}