answersLogoWhite

0


Best Answer

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

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When is better to use global variables rather than utilizing local variables in a program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are global variable?

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


If most variables are local in a program instead of global the result is a program with low or high coupling?

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.


When possible you should avoid using variables in a program.?

global


When possible you should advoid using what variables in a program?

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


What are the differences between global variables and local variables in C plus plus?

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


Why memory is divided into initialized and uninitialized areas?

The program's data segment. This area of memory is allocated by the linker and is used to store the program's global variables, static variables, static arrays and constants. Constants are always initialised, as are static variables, but global variables and static arrays need not be initialised.


whose variables are also known as global variables?

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(); }


What is the Conceptual Memory Map of a C Program?

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.


What is the difference between extern and global?

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.


Why there are no global variables in java?

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


What is the other name of global variables?

Another name of global variable is "EXTERNAL VARIABLES".


What are local variables and global variables?

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.