answersLogoWhite

0


Best Answer

Global (file scope) variable and static global variables both retain their value for the duration of the program's execution. Static global variables are visible only to functions within the file they are declared, while global variables are visible to all compilation units (files) within the linked load module.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

If in a function a variable is declared as

static int a;

The value of a is preserved when the program exits the function and is available when the program returns to the function.

Global variables are visible throughout the program.

A variable declared outside of a function as static has a visibility to only the functions contained in the source file.

Now you will be confused so do your own study until you understand how all this applies, it is very useful stuff to know and later be able to use.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

A static variable is any variable allocated at compile time.

A dynamic variable is one that is allocated at runtime.

There can be only one instance of a static variable, but there may be many instances of a dynamic variable. Dynamic variables may be allocated on the heap or on the stack. Static variables are always allocated in static memory (the program's data segment).

Examples:

int x;

void foo () {

static int y;

int z;

int* p = malloc (sizeof(int));

// ...

free (p);

}

The variable x is declared outside of any function or structure and therefore has global scope. All globals are implicitly static, as are all constant variables.

The variable y is declared inside a function and therefore has local scope (local to the function), but is explicitly static, thus there is only one instance of y.

The variable z also has local scope but is dynamically allocated on the stack each time the function is invoked. Every thread of a process has its own stack and each can invoke the foo() function independently of all others, thus there will be one instance of z for each instance of foo(0.

The variable p is also local scope and is also dynamically allocated on the stack. The memory it refers to, however, has no name of its own (it is anonymous) and is allocated dynamically on the heap (via malloc).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Static is a variable which we can declare globally and whenever we called it while using a program it take it previous value which stored inside it .......

Example :

void print(void):

void main ()

{

print();

print();

print();

}

print(void)

{

static int a;

printf("%d",a);

a=a+1;

}

run this you will see the difference..........

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

They are entirely different things, 'constant' means: not to change its value, 'static' means 'not public' and/or 'not local' variable.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Static

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Distinguish Between Static and Dynamic variable in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between backtracking and dynamic programming?

The only difference between dynamic programming and back tracking is DP allows overlapping of sub problems. (fib(n) = fib(n-1)+ fib (n-2)).


What are the difference between greedy algorithm and dynamic programing?

A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the subproblems do not have to be known at each stage; instead a "greedy" choice can be made of what looks best for the moment.


What is the similar property between dynamic programming and greedy approach?

Both are using Optimal substructure , that is if an optimal solution to the problem contains optimal solutions to the sub-problems


Advantages of dynamic programming?

Dynamic programming enables you to develop sub solutions of a large program.the sub solutions are easier to maintain use and debug.And they possess overlapping also that means we can reuse them.these sub solutions are optimal solutions for the problem


What are the two properties that characterise a good dynamic programming problem?

Dynamic programming is a technique for solving problem and come up an algorithm. Dynamic programming divide the problem into subparts and then solve the subparts and use the solutions of the subparts to come to a solution.The main difference b/w dynamic programming and divide and conquer design technique is that the partial solutions are stored in dynamic programming but are not stored and used in divide and conquer technique.

Related questions

What is the difference between static and dynamic programming?

in static programming properties, methods and object have to be declared first, while in dynamic programming they can be created at runtime. This is usually due to the fact that the dynamic programming language is an interpreted language.


Difference between greedy algorithm and dynamic programming?

the basic difference between them is that in greedy algorithm only one decision sequence is ever generated. where as in dynamic programming many decision sequences are generated.


Distinguish detween static and dynamic gain from trade?

Distinguish detween static and dynamic gain from trade?


What is the difference between backtracking and dynamic programming?

The only difference between dynamic programming and back tracking is DP allows overlapping of sub problems. (fib(n) = fib(n-1)+ fib (n-2)).


Is quick sort is an example of dynamic programming algorithm?

quick sort is a divide and conquer method , it is not dynamic programming


What is difference between linear and dynamic programming?

Dynamic programming (DP) has been used to solve a wide range of optimizationproblemsWhen solving a problem using linear programming, specific inequalities involving the inputs are found and then an attempt is made to maximize (or minimize) some linear function of the inputs.


What has the author Ronald A Howard written?

Ronald A. Howard has written: 'Dynamic Probabilistic Systems, Volume II' 'Dynamic programming and Markov processes' -- subject(s): Dynamic programming, Markov processes


What has the author Sven Dano written?

Sven Danoe has written: 'Nonlinear and dynamic programming'


What are the positives of dynamic programming?

There are several positives of dynamic programming. Dynamic programming allows a person to develop sub solutions for a large program. Having sub solutions makes it easier to maintain use of a program. Sub solutions also make it easier to debug a program.


What are the difference between greedy algorithm and dynamic programing?

A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the subproblems do not have to be known at each stage; instead a "greedy" choice can be made of what looks best for the moment.


What has the author Bojan Rumen Bojkov written?

Bojan Rumen Bojkov has written: 'Application of variable stage lengths in iterative dynamic programming to time optimal control and free final time problems'


Advantages of Typeless programming language?

* In a typeless language, a variable can contain any kind of value (numeric, string, boolean). * Typeless languages are very flexible and dynamic, resulting in quick turn around of code.