Local Variables and Global Variables
1-Local variables are those variables which declared inside the function
2- These variable are local to the function in which they are defines. The local
variable have meaning only in the function where they are defined.
3- Local variables exists only while the function that contains them is
executing....
for example
myfunction()
{
int first_no, second_no;// Local Variables
char firstchar, second_char;// Local Variables
}
Global Variable(External)
1-Global or External variables are not declared with in a specific function.
2- After a global variable has been declared , it is avaliable to all the
functions of the program.
3- The Global variable cannot be defined in the function. They are available to the
function by their definition itself.
4- If Local variables are given the same name as the global variable with in a
function, the global variables will not be available to that function.
int myrollno, yourrollno;// Global Variables
void main()
{
int marks, per;//local Variables
printf("");
result();
getch();
}
void result()
{
myrollno=1;
yourrollno=2;
printf("");
printf("");
}