1.

How can one differentiate between local variables and global variables?

Answer»

Global variables and Local variables can be DISTINGUISHED based on their features.

Global variables possess the FOLLOWING features:

  • Variables DEFINED outside of a function or in a global space are known as global variables.
  • If a variable in the function is ever GIVEN a new value, it is implicitly local, and we must explicitly designate it as 'global.' To make a variable global, we must declare it with the global keyword.
  • From anywhere in the programme, any function can ACCESS and modify the value of global variables.

Local Variables possess the following features:

  • Any variable declared within a function is referred to as a local variable. This variable only exists in local space; it does not exist in global space.
  • If a variable receives a new value anywhere in the function, it is assumed to be local.
  • The local body is the only part where these variables can be accessed.


Discussion

No Comment Found