answersLogoWhite

0


Best Answer

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

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Whose variables are also known as global variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why are troubleshooter bugs more difficult with global variables?

Global variables are accessible to any code making it much more difficult to determine when and where a global is being modified. They can also lead to data-races whenever two threads try to write to the same global at the same time, or one tries to read the global while another is modifying it. The more complex the global the greater the risk. Globals are not necessarily bad provided they are thread-safe and genuinely represent a truly global concept. If not, use a local variable instead.


What are the inbuilt final methods in java?

final methods and variables are that whose values couldn't change.not even run time also.


What are the different storage class in c?

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.


What is the storage allocation and scope of global extern static local and register variables?

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)


What are the five advantages and five disadvantages of using global variables?

The only case where a global variable is advantageous is when that global is a constant variable and it represents a truly global concept. The value of PI, for instance, is a truly global concept and it has a constant value. The exchange rate between dollars and Sterling is also a truly global concept, but it is non-constant and should not be declared global. Global (non-constant) variables are problematic because it can be difficult to track down all the places that interact with a global, especially if the global has external linkage. Even if that is not a problem in itself, a global cannot cater for both single-threaded and multi-threaded applications. If intended purely for single-threaded applications then there will be no synchronisation mechanism, thus it cannot be used in a multi-threaded application as this could lead to a data race. Conversely, if intended purely for multi-threaded applications, it will have a synchronisation mechanism but this could lead to performance issues on single-threaded applications where synchronisation is not required. In trivial applications, global variables can often be useful because the scope of a global can be well-defined. But in non-trivial applications, it becomes more difficult to limit the scope of a global. One way to limit the scope is to declare the global variable static, thus limiting its scope to the translation unit in which it is declared (static global variables cannot have external linkage). However, by limiting the scope, the variable is no longer a truly global concept.

Related questions

What is the relationship between two variables also known as?

A correlation


How do you create a global variable in a program?

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;


The greenhouse effect is also known as?

It is also know as global warming.


Why are troubleshooter bugs more difficult with global variables?

Global variables are accessible to any code making it much more difficult to determine when and where a global is being modified. They can also lead to data-races whenever two threads try to write to the same global at the same time, or one tries to read the global while another is modifying it. The more complex the global the greater the risk. Globals are not necessarily bad provided they are thread-safe and genuinely represent a truly global concept. If not, use a local variable instead.


What is the difference between a manipulated and responding variable?

Manipulated variables are also known as independent variables. These are the variable which you change in an investigation. Plotted on the x axis.


What is a inderpendent variable?

Dependent variables and independent variables refer to values that change in relationship to each other. The dependent variables are those that are observed to change in response to the independent variables. The independent variables are those that are deliberately manipulated to invoke a change in the dependent variables. In short, "if x is given, then y occurs", where x represents the independent variables and y represents the dependent variables. Depending on the context, independent variables are also known as predictor variables, regressors, controlled variables, manipulated variables, explanatory variables, or input variables. The dependent variable is also known as the response variable, the regressand, the measured variable, the responding variable, the explained variable, the outcome variable, the experimental variable or the output variable. This answer was coppied onto this page by tom hills of falmouth waii


What are the inbuilt final methods in java?

final methods and variables are that whose values couldn't change.not even run time also.


Whose second symphony is aslo known as the resurrection?

Gustav Mahler's second symphony is also known as "The Resurrection".


What are the different storage class in c?

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.


What is the manipulating factor?

The independent variable is also known as the manipulated variable. This is the factor manipulated by the experimenter, and it produces one or more results, known as dependent variables.


What is the storage allocation and scope of global extern static local and register variables?

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)


What is meant by SBC global log in?

SBC Global Login is the largest fixed telephony, broadband, and subscription television services provider in the United States. SBC Global Login is also known as AT&amp;T Inc.