answersLogoWhite

0

we can call global variables in main method by using scope resolution operator(::)

if local and global have same name

for example

int x=10;

main()

{

int x=20;

cout<<x; //x=20

cout<<::x; //x=10

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is the difference between a global variable and a private variable?

The accessibility. The global one: almost everywhere in the code may reference to the global variable directly. The private variable, is private to the declaring module (class, method, assembly) only. Outside of that module has no access to it directly.


What is it called when java allows you to declare methods with the same name in a class?

Yes perfectly Legal Reason: The scope of a variable declared inside a method is only till the method's end. So by defining another variable of the same name inside a different method does not create any issues.


What is the difference between variable declared inside the declaration part and variable declared in scriptlet part?

Variable declared inside declaration part is treated as a global variable, which means after translation of jsp file into servletthat variable will be declared outside the service method as an instance variablethe scope is available to the complete jspVariable declared inside a scriplet will be declared inside a service method as a local variable and the scope is with in the service method.


Which type of research method is used to show cause and effect that one variable causes change in another variable?

The experimental research method is typically used to show cause and effect between variables, where one variable is manipulated to observe the effect on another variable. This method involves randomly assigning participants to different conditions and controlling for extraneous variables to establish a causal relationship.


Where are variables displayed when using the POST method?

When data is POSTed to a PHP script, you may access them from the $_POST super global variable.


What are variable of the scientific method?

what are the variable


Is possible to declare a variable in a method and declare it a main?

The same identifier (variable name) may be used for at most one variable in each scope. Each method has its own scope, in addition to the global scope which is accessible from all others. However, each scope would have a different variable than every other scope despite using the same name for it.


How do you declare global variable in dot net?

I use the session .... Session["var"] = some value or object. Then you can call that variable any time for the users Session. EDIT: Make a public static variable outside of a method and just in the Class.


Which research method assesses how well one variable predicts another without specifying a cause and effect relationship between the variables?

Correlational research method assesses the relationship between two variables without implying causation. It examines how changes in one variable are associated with changes in another variable.


What does manipulated variable mean in a scientific method?

In the scientific method, a manipulated variable, also known as the independent variable, is the factor that is deliberately changed or controlled by the researcher to observe its effect on another variable. This allows scientists to establish cause-and-effect relationships in experiments. By varying the manipulated variable, researchers can gather data on how it influences the dependent variable, which is the outcome being measured.


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


A variable that is declared inside a method is called variable?

It is called a local variable since it only exists inside the method.