what is the difference between local variable and global variable also giving suitable C++ cøde to illustrate both
Answers
Answered by
3
Answer
A variable which is declared within the body of a function and available only within the function is known as local variable.
A variable which is declared outside any function and available to all functions in a program is known as global variable.
To illustrate this, below is the programming example ↓
#include<iostream.h>
float area; //Global variable
void cirarea()
{
float r; //Local variable
cin>>r;
area=3.14*r*r;
cout<<area;
}
void rectarea()
{
float l,b; //Local variable
cin>>l;
cin>>b;
area=l*b;
cout<<area;
}
void main()
{
cirarea();
rectarea();
}
Similar questions