answersLogoWhite

0


Best Answer

A static variable is a variable allocated in static storage.

A local variable is a variable declared inside a function.

A global variable is a variable declared outside of any class or function.

Note that local variables and global variables can both be allocated in static storage.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between a static variable a global variable and a local variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


What is the difference between static function and global static function?

'global static'?! There is no such thing.


What is difference between Static and Global variable?

Static may be local of global -local static variable is limited to the function scope. and retain it's value when function is been called . compiler differentiate static variables with a prefix function name while dealing with same name static variable in different functions. - Global static variable is visible to all the function defined in the file and retain it value but it cannot be used outside this file. now Global Variable --- this variable is also visible to all of the functions inside the file but also can be used outside the file via extern keyword.


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


Which variable is initialized once when program is compiled?

global and static


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.


Write the difference between global variable and static variable in context to function with suitable example?

Static VariableA variable that exists in only one location and is globally accessible by all instances of a class and also a variable for which memory remains allocated as long as the program executes.Global VariableA variable that can be accessed by all parts of a program so it does not belong to any subroutine in particular and can therefore can be accessed from any context in a program


Describe about storage allocation and scope of global extern static local and register variables?

Global Varible: The variable which is declared as "Global" one : having the preveleges to use and access that variable in any class and object( means any where in the program) just like PUBLIC keyword in OOPS concepts. Static Variable : If we declare a variable as Static , then it wont have the permission to access that variable through out the program and u have to use it inside the class or object which u declared itself. All the Best Annapurna


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

First, lets speak about the scope of a variable. The scope of a variable is the section of the application that can see and manipulate that variable. If the variable is declared in a procedure when that procedure is called, only that procedure can use that variable. Hence that variable is considered "Local". Now Static. Static variables are variables that are created with the static key word as in:- function ab(var1 as integer)as integer static iTotal as integer itotal =iTotal + var1 (rest of ccode goes here) end function Now when this function is called the first time, iTotal will be assigned the value of var1. The next time the function is called, iTotal will retain the previous value and the new value of var1 will be added to it. Hope this helps. (theTeacha) Static variables life time is not under any scope.It initializes only one time from creation to delete.let me explain by a pgm. void main() { int a=1; static s=1; int k=0; for(k=0;k<1;k++) { i++; s++; main(); } printf("%d is i",&i); printf(%d is S",&s); getch(); } Output will be 2 is i 3 is s It Shows that local variable initialize every time the function call.But Static variable initializes only once <><><> For a variable, static means it keeps its value even when the enclosing code is not active--out of scope. A static variable is assigned to a fixed memory location when the program runs, so it is possible to examine a static variable at any time the program is active, even when the function where the var is declared is not active. A local variable is dynamically allocated storage space when a function is called, and its storage is given up when the function ends, so it only exists while the function is executing. For a function, static declaration means it can only be called from functions in the same file (in C).


what is the difference between final and static keywords?

static: we can use the keyword static either to method or to a variable. when we declare to a method,(eg: public static void main(String args[]),we can use this method without any object. when we use to a variable,there will be only one instance of that variable irrespective of how many objects that get created of that class. Final: Usage of final to method or to a variable makes them as constant. It's value cannot be changed...


What is the difference between complex permittivity and static dielectric conatant?

What is the difference between complex permittivity and static dielectric conatant?