Software and Applications (non-game)
Computer Programming
Database Programming
C Programming

Where does global static local register variables free memory and C Program instructions get stored?

373839

Top Answer
User Avatar
Wiki User
2005-10-30 03:39:34
2005-10-30 03:39:34

* These are all implementation defined. Access to `register' specified indentifiers should be as fast as possible, so the compiler may place the value in a machine register. However, the compiler is free to treat a `register' declaration as an `auto' declaration. * Where free memory is maintained is an OS specific concept. Instructions are generally stored in code segement. Local Variables are stored in Stack. Register variables are stored in Register. Global & static variables are stored in data segment. The memory created dynamically are stored in Heap And the C program instructions get stored in code segment.

12
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0

Related Questions

User Avatar

AnswerLocal Variables are stored in Stack. Register variables are stored in Register. Global variables are stored in data segment. The memory created dynamically are stored in Heap And the C program instructions get stored in code segment and the extern variables also stored in data segment. Nooo NoooStatic variable will be stored in .BSS segment... (Block Started By Symbol)

User Avatar

Variables that are declared globally outside every program are called global variables.

User Avatar

Coupling is the interdependency of a program. A program that uses local variables is more independent than one that uses global variables. Therefore, the program would be considered to have lower coupling.

User Avatar

Global variables don't have special place where it can be stored in. OS decides where to save it. Global variables are special only in the way that all blocks of your program can get access to it.

User Avatar

Extern and Global are the storage space in C program. Global provides us to access the variables from anywhere inside the program only whereas Extern provides us to access the variables from outside that program, i,e., some other program.

User Avatar

Global Variables Or: variables with names longer than 128 characters.

User Avatar

Global variables can be seen in all blocks of your program, when local variables are visible only within the block where it's declared.

User Avatar

In my opinion it is rarely a good idea to use global variables, unless you need to refer to them across modules, or their values need to be keep for a long period of program execution. Local variables should always be used when their lifetime is short, usually only in the module they are declared in. Global variables lifetime will be for the length of the program execution.

User Avatar

a. Register values b. Heap memory c. Global variables d. Stack memory

User Avatar

The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }

User Avatar

Global variables are globally accessible. Java does not support globally accessible variables due to following reasons:The global variables breaks the referential transparencyGlobal variables creates collisions in namespac

User Avatar

Extern is not a storage allocation specifier, it declares external linkage. That is, the declared variable or constant will be defined in a separate translation unit. Variables declared in global scope are allocated in static memory, as are all constants and static local variables. Local (non-static) variables are allocated on the (current) call stack. In multi-threaded applications, each thread has its own call stack. Register variables are automatic variables allocated within a CPU register, however the language compiler ultimately decides when or indeed if this is appropriate.

User Avatar

constant variables are not stored anywhere..where ever they r present in the program the compilier at compilation time replaces these varibles by their values...however the local variables are stored in stack memory & global and static variables are stored in data segement of the program....

User Avatar

C++ has 4 distinct regions for memory distribution Stack : This region is used for function calls' return addresses , arguments and local variables Heap : This region is for dynamic allocation of memory (dynamic variables created on run time use this memory , aka RAM) Global Variables : This is used for global variables defined by the programmer Program Code : This region is for the program code.

User Avatar

The four storage classes in C are: automatic, static, external and register. Note that storage classes are not classes in the object-oriented programming sense, they simply define the scope (visibility) of a variable.Automatic Variables (auto)All local variables are automatic by default so we seldom see the auto keyword in code. Local variables are variables declared at function scope.Static Variables (static)All global variables are static by default. Global variables are variables declared at file scope (outside of any function). Static variables can also be explicitly declared inside functions to override the default automatic storage class. All static variables, whether global or local, are allocated within the program's data segment (static memory) and do not fall from scope even if declared locally. All static variables are initialised to zero by default.It's best to avoid the use of global variables unless they are declared constant (const) as it can be difficult to keep track of all the places where a global variable is being operated upon (accessed or assigned to). This can lead to data races in multi-threaded applications unless we take steps to synchronise all access and assignment operations upon the variable. For that reason it's best to keep variables as localised as possible, passing arguments into functions whenever we need to cross scopes. Non-constant global variables should really only be considered if they truly represent a global concept within the file in which they are declared.External Variables (extern)External storage can only be applied to a global variable declared outwith file scope. That is, when a global variable is declared in one file, any external file can gain access to that same global variable simply by declaring the same name and type but with external storage. It follows that external variables are also static variables and is the only case where a variable has two storage classes. Note the local static variables (including local constant variables) cannot be declared external, they are local to the function in which they are declared.This is another reason why it is best to avoid using too many global variables. While we can generally keep track of which code can access a global variable at file scope we have no means of limiting access from outwith that file. Again, prefer local variables to global variables whenever possible.Register Variables (register)A register variable is a variable that we wish to allocate to a CPU register rather than in RAM. Register variables must be no larger than the word-length of the machine and should only be used when we explicitly require fast access to the variable, such as loop counters, accumulators and pointer variables. Note that CPU registers have no address (no identity we can refer to) so we cannot use the unary '&' operator to take the address of a register variable. This means we cannot use pointers to refer to them indirectly which, in turn, means we can only pass them to functions by value (not by reference). However, to do so would defeat the purpose of using the register storage class.Given the limited number of registers available, there is no guarantee that a register variable will actually be allocated to a register; the register keyword is merely a hint to the compiler. It should be noted that modern compilers are extremely good at optimising code so there is seldom any need to explicitly declare register variables.

User Avatar

Global variables can be seen in all blocks of your program, when local variables are visible only within the block where it's declared. hope this helps ...harry hill

User Avatar

Another name of global variable is "EXTERNAL VARIABLES".

User Avatar

The term variables imply that those things may be changed or assigned with new value (at numerous places). This make the program harder to debug because it will be difficult to know when and where a global variable being changed and what was the consequence of that value changed.

User Avatar

1.In computer programming, a global variable is a variable that is accessiblein every scope.2.There are some variables that are used in more than one function.suchvariables are called global variables.3.Usually,they are declared in global declaration section that is outsideof all functions.4.In this section,we can also declare all user-defined functions.DECLARATION:int global =5;

User Avatar

Auto is one of the four storage classes in c. This is the default storage class. The auto storage class can be used only inside functions, i.e. only to declare local variables and not to declare global variables. All the local variables are by default auto variables. Other storage classes are: Register - variables declared may get stored in CPU registers instead of RAM Static - default storage class for global variables extern - defines global variables that is visible to all object modules

User Avatar

Global variables are named storage locations that are allocated (and possibly initialized) when the program is loaded. Global variables are accessible by name from within any function. In C source, a global is a variable that is declared outside of any function, without an extern or static storage class specifier.The use of global variables without good justification is generally considered bad programming style, as it creates cohesion between functions and between modules, allows functions to have side-effects, and causes lots of confusion if some functions declare automatic variables with the same names as global variables.

User Avatar

Local variables: These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main program. As such, they are normally implemented using a stack. Local variables cease to exist once the function that created them is completed. They are recreated each time a function is executed or called. Global variables: These variables can be accessed (ie known) by any function comprising the program. They are implemented by associating memory locations with variable names. They do not get recreated if the function is recalled.

User Avatar

Variables that the program can use everywhere in the program. Example: int x = 5; int main(void) { x = 6; foo(); return 0; } void foo(void) { x = 5; }

User Avatar

You declare global and local variables in pseudocode the same way you declare them in real code. You place local variables within blocks, and you place global variables outside of all blocks.

User Avatar

The only disadvantage of a global variable is that you cannot directly encapsulate them. Other than that, there is no real disadvantage of global variables.


Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.