answersLogoWhite

0

You declare it outside of any class or function.

Example:

#include <iostream>

using namespace std;

int globalint = 52;

int main(){

cout<<globalint<<endl;

globalint=73;

cout<<globalint<<endl;

return(0)

}

Or, If you like C code:

#include <stdio.h>

int globalint = 52;

int main(){

printf ("GlobalInt: %d\n", globalint);

globalint=73;

printf ("GlobalInt: %d\n", globalint);

exit(0);

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How can you declare global and local variable in pseudocode?

A local variable is a variable declared inside a construct, such as a class or function, while a global variable is a variable declared outside of any construct.


How do you declare local and global variables in pseudo code?

Pseudocode is not a programming language (it's specifically intended for human interpretation), so there is no need to declare variables, you simply define them as and when you require them. For instance: Let x = 42 Let y = x * 2


What will you do in order to share a variable among multiple files?

Almost all High end scripting languages, in order to share a Variable with multiple files, You would have to declare a Global Variable.


Why all variables are declared with in the function?

It is not necessary to to declare variables inside the function in C. If you declare a variable inside a function, the variable becomes local for the function and another variable of same name can be declared in any other function, but you can not use the variable declared in other function. When you declare any variable outside the function body then the variable becomes global and can be used in any function of the program. Note: errno is an example for a variable declared outside any function.


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;


What is the difference between declaring static variable as local and global?

There are two ways to declare varibles. 1. Locally 2. Globally When you declare a variable locally in any function that means it is only accessible by that function. When you declare a variable globally so it is accessible by all the functions in the program. Declaring variables with static keyword means you are setting its value null.


Can we declare register variable as global?

Globals and statics are both allocated in static memory. Locals are allocated on the stack.


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.


Member modifier 'public' must precede member type and name means in computer C language?

While you declaring the global variable you should declare it correctly... This problem mostly arise because any one of the data type in global should not have variable.


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.


What is the difference between global variable and extern variable?

Global variables are non-local variables. That is, variables that are not defined in a function or class. They are globally accessible to all code in the same translation unit. External variables are global variables that have external linkage; they are accessible across translation units.