answersLogoWhite

0

Different between local and global

User Avatar

Anonymous

9y ago
Updated: 3/18/2022

The scope or the life span. The life span is from the birth (allocation) to death (deallocation).

The life span of a global variable starts when the application is invoked. It dies when the application terminated. During the execution of the application , this global variable is available to any program unit within that application.

The life span of a local variable, well, only locally. "Local" means a component, a method (subroutine), or even within a bracket ({} or BEGIN-END) of a statement.

Outside of that block of codes, that local variable does not exist, hence cannot be accessed or referenced. Also, the same name of that local variable may be declared again in another local area without conflict, nor memory of the previous one.

For languages similar to C:

for (int i = 0; i < 100; i++)

{

// i can be referenced within { }, and within the for() control itself

}

for (int i = -1; i > -200; i--)

{

// this i is different from the i in the previous for-loop

}

Some computer language would allow you to declare a local variable with the same name as the global one (for example, there are global::X and local::X, but the code only refer as X). Most of the computer language would replace X with local::X at compile time, some would replace it with global::X) Some languages may not have the notion of local variables, everything is global, and some would not have the notion of global variable, but would provide a mean to act like one.

User Avatar

Angela Veum

Lvl 13
3y ago

What else can I help you with?

Related Questions

Difference between global optimization and partial optimization?

essential diffrence between global and local optimization


What is the difference between local and global revision?

that they are not the same thing


What are similarities between global winds and local winds?

they aren't.


How does the Global advertising differ from local advertising?

Global would be advertising in many different countries, while Local advertising would be in a certain city or district.


What is the difference between a local and a global revision?

A local revision focuses on specific words, phrases, and sentences; a global revision addresses larger aspects of the work.


Definition of global-local continuum?

the notion that what happens at the global scale has a direct effect on what happens at the local scale, and vice versa. this idea posits that the world is comprised of an interconnected series of relationships that extend across space. Source: Human Geography: People, Place, and Culture, 8th Edition


What is the difference between local and global memory allocation?

global memory it is decide outside of your scope and we can access it in all of your scope


How are global variable different from local variable in Visual BASIC?

A global variable is available for use throughout the program. It is normally declared outside any procedure. A local variable is only available for use in the procedure it was declared in. Most variables are local, but there will be occasions when you want different procedures to be able to use the same variable. This is when you use a global variable.


What is different between local and global navigation bar?

I assume that "local" navigation is navigation affordances that are available on one web page, but not others. Global navigation appears on every page of a web site. Usually found in the form of a bar at the top of the page with all the major parts of the site reflected.


How are global winds and local find similar?

Global winds are local winds.


What is relationship between local media and global media?

Local media focuses on news and events within a specific region, while global media covers events on an international scale. Local media often provides a more detailed and in-depth analysis of local issues, while global media offers a broader perspective on worldwide events. The relationship between the two can help audiences understand how local events are interconnected with global issues.


Is a global variable a non-local variable?

True, a variable cannot be both global and local. But if a global and a local variable share the same name, the local one will hide the global.