Give an example in a programming language that youre familia

Give an example in a programming language that you’re familiar with in which a variableis alive but not in scope.

Solution

int main()
{
int x=10;
display();
cout<<x;
}
void display()
{
cout<<\" hello \";
}

Explanation :
In the above example, variable x lives throughout the main function even during execution the of display function which prints \"hello\".But the variable x scope is only the main function hence it is not available in the display functiin

Give an example in a programming language that you’re familiar with in which a variableis alive but not in scope.Solutionint main() { int x=10; display(); cout&

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site